public HashMap<Integer, ArrayList<Double>> createFeatureMatrix(int vocabSize,int embeddingDimension) throws NullPointerException
/*
*Weight vector for each of the word is initialized here.
*/
{
HashMap<Integer, ArrayList<Double>> featureMatrix = new HashMap<Integer, ArrayList<Double>>();
for(int i =0 ; i< vocabSize; i++){
featureMatrix.put(i,wordFeauture(embeddingDimension));
}
return featureMatrix;
}//end of createFeatureMatrix
private ArrayList<Double> wordFeauture(int a) {
Double ranVal;
Random rand = new Random();
ArrayList<Double> arrList = new ArrayList<Double>();
for(int i =0 ; i< a; i++){
ranVal = rand.nextGaussian();
arrList.add(ranVal);
}
return arrList;
}
private ArrayList<Double> getContextFeatureVector(ArrayList<String> Ngram,HashMap<String,Integer > FrequentWordIndex,
HashMap<Integer, ArrayList<Double> > wordFeatureMatrix) throws NullPointerException
/*INPUT :Ngram, Vocabulary Index
*RETURNS:Feature Vector of context of given N-gram.
*/
{
int contextSize = Ngram.size()-1;
System.out.println("getContextFeatureVector: Context Size:"+ contextSize);
System.out.println(Ngram);
ArrayList<Double> contextFeature = new ArrayList<Double>();
contextFeature =wordFeatureMatrix.get(FrequentWordIndex.get(Ngram.get(0).toLowerCase()));
System.out.println(Ngram.get(0));
//System.out.println(contextFeature);
for(int i =1 ; i < contextSize; i++){
//ArrayList<Double> arrList = new ArrayList<Double>();
System.out.println(Ngram.get(i));
//arrList = wordFeatureMatrix.get(FrequentWordIndex.get(Ngram.get(i).toLowerCase()));
System.out.println(wordFeatureMatrix.get(FrequentWordIndex.get(Ngram.get(i).toLowerCase())).size());
//System.out.println("getContextFeatureVector:feature vector:"+arrList);
//System.out.println("getContextFeatureVector:feature vector size:"+arrList.size());
//contextFeature.addAll(wordFeatureMatrix.get(FrequentWordIndex.get(Ngram.get(i).toLowerCase())));
//System.out.println("getContextFeatureVector:context vector size:"+contextFeature.size());
}
//System.out.println(contextFeature);
System.out.println("Size of context Feature"+contextFeature.size());
return contextFeature;
}