• API
• FAQ
• Tools
• Trends
• Archive
daily pastebin goal
35%
SHARE
TWEET

# Untitled

a guest Apr 21st, 2012 33 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
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();
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());