This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Apr 21st, 2012  |  syntax: Java  |  size: 2.42 KB  |  views: 25  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.   public HashMap<Integer, ArrayList<Double>>  createFeatureMatrix(int vocabSize,int embeddingDimension) throws NullPointerException
  2.         /*
  3.          *Weight vector for each of the word is initialized here.
  4.          */
  5.         {
  6.                 HashMap<Integer, ArrayList<Double>>  featureMatrix = new HashMap<Integer, ArrayList<Double>>();
  7.                 for(int i =0 ; i< vocabSize; i++){
  8.                         featureMatrix.put(i,wordFeauture(embeddingDimension)); 
  9.                 }
  10.                 return featureMatrix;
  11.         }//end of createFeatureMatrix
  12.  
  13.  
  14.  
  15. private ArrayList<Double> wordFeauture(int a) {
  16.                 Double ranVal;
  17.                 Random rand = new Random();
  18.                 ArrayList<Double> arrList = new ArrayList<Double>();
  19.                 for(int i =0 ; i< a; i++){
  20.                         ranVal = rand.nextGaussian();
  21.                         arrList.add(ranVal);
  22.                 }
  23.                 return arrList;
  24.         }
  25.  
  26.  
  27.    private ArrayList<Double> getContextFeatureVector(ArrayList<String> Ngram,HashMap<String,Integer > FrequentWordIndex,
  28.                                                   HashMap<Integer, ArrayList<Double> > wordFeatureMatrix) throws NullPointerException                                                                    
  29.     /*INPUT  :Ngram, Vocabulary Index
  30.      *RETURNS:Feature Vector of context of given N-gram.
  31.      */
  32.     {  
  33.         int contextSize = Ngram.size()-1;
  34.         System.out.println("getContextFeatureVector: Context Size:"+ contextSize);
  35.         System.out.println(Ngram);
  36.         ArrayList<Double> contextFeature = new ArrayList<Double>();
  37.         contextFeature =wordFeatureMatrix.get(FrequentWordIndex.get(Ngram.get(0).toLowerCase()));
  38.         System.out.println(Ngram.get(0));
  39.         //System.out.println(contextFeature);
  40.        
  41.         for(int i =1 ; i < contextSize; i++){
  42.                 //ArrayList<Double> arrList = new ArrayList<Double>();
  43.                 System.out.println(Ngram.get(i));
  44.                 //arrList = wordFeatureMatrix.get(FrequentWordIndex.get(Ngram.get(i).toLowerCase()));
  45.                 System.out.println(wordFeatureMatrix.get(FrequentWordIndex.get(Ngram.get(i).toLowerCase())).size());
  46.                 //System.out.println("getContextFeatureVector:feature vector:"+arrList);
  47.                 //System.out.println("getContextFeatureVector:feature vector size:"+arrList.size());
  48.                  //contextFeature.addAll(wordFeatureMatrix.get(FrequentWordIndex.get(Ngram.get(i).toLowerCase())));
  49.                 //System.out.println("getContextFeatureVector:context vector size:"+contextFeature.size());
  50.         }
  51.         //System.out.println(contextFeature);
  52.         System.out.println("Size of context Feature"+contextFeature.size());
  53.         return contextFeature;
  54.     }
clone this paste RAW Paste Data