使用doc2vec从一行文本中识别产品名称

时间:2017-07-19 11:10:06

标签: doc2vec

我有一行直线文字。从行文本列中,我将列出与产品名称列表类似的名称。我正在使用Doc2Vec来解决问题。但我的结果非常糟糕。对于这个问题,哪种方法正确?

我的数据如下: LINE TEXT: 托盘 10公斤鸡肉 焊接金属 后勤 第100个主要,bolulvedour大道 19号主要ST 约翰 5670987

和我用来获得最相似名字的产品列表是 mat_subset = [英国鞋码10,超干饰条,重量10kgs,托盘等)。

我的行文本是我的OCR输出,相当不错。 我使用的Doc2Vec代码如下。

s_data=mat['LINETEXT']
line_txt = pd.DataFrame()
line_txt['sentences']=s_data
line_txt['sentences']=line_txt['sentences'].astype(str)
line_txt['tokenized_sents'] = line_txt.apply(lambda row: nltk.word_tokenize(row['sentences']), axis=1)

sentences= []
for item_no, line in enumerate(line_txt['tokenized_sents'].values.tolist()):
    sentences.append(LabeledSentence(line,[item_no]))
# MODEL PARAMETERS   
dm = 1 # 1 for distributed memory(default); 0 for dbow 
cores = multiprocessing.cpu_count()
size = 300
context_window = 50
seed = 42
min_count = 1
alpha = 0.5
max_iter = 200

# BUILD MODEL
model = gensim.models.doc2vec.Doc2Vec(documents = sentences,
dm = dm,
alpha = alpha, # initial learning rate
seed = seed,
min_count = min_count, # ignore words with freq less than min_count
max_vocab_size = None, # 
window = context_window, # the number of words before and after to be used as context
size = size, # is the dimensionality of the feature vector
sample = 1e-4, # ?
negative = 5, # ?
workers = cores, # number of cores
iter = max_iter)

overalldf=[]
for line in mat_subset:
    infer_vector = model.infer_vector(line)
    similar_documents = model.docvecs.most_similar([infer_vector], topn = 10)
    df.columns=["sentence",'Similarity']
    overalldf.append(df)

final=pd.concat(overalldf)

这是我用过的代码。其中mat_subset是我的产品名称列表。我是python的新手,如果我做错了就纠正我

1 个答案:

答案 0 :(得分:0)

Doc2Vec可能有用,如果您有足够的数据,可以使用任何数量的其他基于关键字或文本到矢量的方法(比如通过稀疏的词袋向量表示产品)。

但是,如果不知道数据的局限性,以及您以前尝试过的任何内容是否正确完成,以及您对#34;足够好的客观评价"结果将是,不可能给出具体的答案。