0

I am beginner of python language,natural language processing,deep learning,neural networks.I want to execute a program which convert text file into vector by using word2vec in python..someone please help me

import math 
import nltk file = "/home/stephy/Demo/textfile.txt" 
import numpy as np 

def loadGloveModel(gloveFile): 
    with open(gloveFile, encoding="utf8" ) as f: 
        content = f.readlines() 
    model = {} for line in content: 
        splitLine = line.split() 
        word = splitLine[0] 
    embedding = np.array([float(val) for val in splitLine[1:]])  
    model[word] = embedding 
    print ("Done.",len(model)," words loaded!") 
    return model 

model= loadGloveModel(file) 
print (model['file']) 
petezurich
  • 9,280
  • 9
  • 43
  • 57
  • 1
    Show what you've tried and where you've having a problem. – Andrew Mortimer Sep 22 '18 at 07:06
  • @AndrewMortimer import math import nltk file = "/home/stephy/Demo/textfile.txt" import numpy as np def loadGloveModel(gloveFile): print ("Loading Glove Model") with open(gloveFile, encoding="utf8" ) as f: content = f.readlines() model = {} for line in content: splitLine = line.split() word = splitLine[0] embedding = np.array([float(val) for val in splitLine[1:]]) model[word] = embedding print ("Done.",len(model)," words loaded!") return model model= loadGloveModel(file) print (model['file']) – Stephy Maria A.K Sep 22 '18 at 07:31
  • I am new to stack overflow and don't know the exact formatting of the code. Sorry for the excuse – Stephy Maria A.K Sep 22 '18 at 07:33
  • Please recheck if code is added correctly to your post. Btw: In the editor there is a button with curly brackets. Simply paste your code, activate it and press the button. See also this: https://stackoverflow.com/help/formatting – petezurich Sep 22 '18 at 09:52

0 Answers0