我在 word2vec gensim 中得到 'single' 个字符作为学习词汇作为输出
I get 'single' characters as learned vocabulary on word2vec genism as an output
我是 word2vec 的新手,我已经通过 word2vec 训练了一个文本文件以进行特征提取,但是当我查看训练过的单词时,我发现它是单个字符而不是单词,我在这里错过了什么?有人帮忙
我尝试将标记而不是原始文本输入模型
import nltk
from pathlib import Path
data_folder = Path("")
file_to_open = data_folder / "test.txt"
#read the file
file = open(file_to_open , "rt")
raw_text = file.read()
file.close()
#tokenization
token_list = nltk.word_tokenize(raw_text)
#Remove Punctuation
from nltk.tokenize import punkt
token_list2 = list(filter(lambda token : punkt.PunktToken(token).is_non_punct,token_list))
#upper to lower case
token_list3 = [word.lower() for word in token_list2]
#remove stopwords
from nltk.corpus import stopwords
token_list4 = list(filter(lambda token: token not in stopwords.words("english"),token_list3))
#lemmatization
from nltk.stem import WordNetLemmatizer
lemmatizer = WordNetLemmatizer()
token_list5 = [lemmatizer.lemmatize(word) for word in token_list4]
print("Final Tokens are :")
print(token_list5,"\n")
print("Total tokens : ", len(token_list5))
#word Embedding
from gensim.models import Word2Vec
# train model
model = Word2Vec(token_list5, min_count=2)
# summarize the loaded model
print("The model is :")
print(model,"\n")`enter code here`
# summarize vocabulary
words = list(model.wv`enter code here`.vocab)
print("The learned vocabulary words are : \n",words)
Output- ['p', 'o', 't', 'e', 'n', 'i', 'a', 'l', 'r', 'b', 'u', 'm', 'h', 'd', 'c', 's', 'g', 'q', 'f', 'w', '-']
Expected -[ 'potenial', 'xyz','etc']
Word2Vec
需要其训练语料库是一个序列,其中每个项目 (text/sentence) 都是一个 字符串标记列表 。
如果您改为传递原始字符串文本,每个文本将显示为 单字符标记列表,这将导致您的最终词汇表再看,所有学到的 'words' 都只是单个字符。
所以,仔细看看您的 token_list5
变量。因为它是一个列表,所以 token_list5[0]
是什么? (它是一个字符串列表吗?)什么是 token_list5[0][0]
? (是一个完整的词吗?)
我是 word2vec 的新手,我已经通过 word2vec 训练了一个文本文件以进行特征提取,但是当我查看训练过的单词时,我发现它是单个字符而不是单词,我在这里错过了什么?有人帮忙
我尝试将标记而不是原始文本输入模型
import nltk
from pathlib import Path
data_folder = Path("")
file_to_open = data_folder / "test.txt"
#read the file
file = open(file_to_open , "rt")
raw_text = file.read()
file.close()
#tokenization
token_list = nltk.word_tokenize(raw_text)
#Remove Punctuation
from nltk.tokenize import punkt
token_list2 = list(filter(lambda token : punkt.PunktToken(token).is_non_punct,token_list))
#upper to lower case
token_list3 = [word.lower() for word in token_list2]
#remove stopwords
from nltk.corpus import stopwords
token_list4 = list(filter(lambda token: token not in stopwords.words("english"),token_list3))
#lemmatization
from nltk.stem import WordNetLemmatizer
lemmatizer = WordNetLemmatizer()
token_list5 = [lemmatizer.lemmatize(word) for word in token_list4]
print("Final Tokens are :")
print(token_list5,"\n")
print("Total tokens : ", len(token_list5))
#word Embedding
from gensim.models import Word2Vec
# train model
model = Word2Vec(token_list5, min_count=2)
# summarize the loaded model
print("The model is :")
print(model,"\n")`enter code here`
# summarize vocabulary
words = list(model.wv`enter code here`.vocab)
print("The learned vocabulary words are : \n",words)
Output- ['p', 'o', 't', 'e', 'n', 'i', 'a', 'l', 'r', 'b', 'u', 'm', 'h', 'd', 'c', 's', 'g', 'q', 'f', 'w', '-']
Expected -[ 'potenial', 'xyz','etc']
Word2Vec
需要其训练语料库是一个序列,其中每个项目 (text/sentence) 都是一个 字符串标记列表 。
如果您改为传递原始字符串文本,每个文本将显示为 单字符标记列表,这将导致您的最终词汇表再看,所有学到的 'words' 都只是单个字符。
所以,仔细看看您的 token_list5
变量。因为它是一个列表,所以 token_list5[0]
是什么? (它是一个字符串列表吗?)什么是 token_list5[0][0]
? (是一个完整的词吗?)