【发布时间】:2020-05-26 00:24:29
【问题描述】:
我有一种情况,我需要从可用的职位描述中提取正在申请工作的特定申请人的技能,并将其完全存储为一个新列。 数据框 X 如下所示:
Job_ID Job_Desc
1 Applicant should posses technical capabilities including proficient knowledge of python and SQL
2 Applicant should posses technical capabilities including proficient knowledge of python and SQL and R
结果输出应如下所示:
Job_ID Skills
1 Python,SQL
2 Python,SQL,R
我已经使用 tf-idf count vectorizer 来获取 Job_Desc 列中最重要的单词,但我仍然无法在输出中获取所需的技能数据。这可以通过 Word2Vec 使用 skip gram 或 CBOW 模型以某种方式实现吗?
我的代码如下所示:
from sklearn.feature_extraction.text import CountVectorizer
cv=CountVectorizer(max_df=0.50)
word_count_vector=cv.fit_transform(X)
from sklearn.feature_extraction.text import TfidfTransformer
tfidf_transformer=TfidfTransformer(smooth_idf=True,use_idf=True)
tfidf_transformer.fit(word_count_vector)
def sort_coo(coo_matrix):
tuples = zip(coo_matrix.col, coo_matrix.data)
return sorted(tuples, key=lambda x: (x[1], x[0]), reverse=True)
def extract_topn_from_vector(feature_names, sorted_items, topn=10):
"""get the feature names and tf-idf score of top n items"""
#use only topn items from vector
sorted_items = sorted_items[:topn]
score_vals = []
feature_vals = []
for idx, score in sorted_items:
fname = feature_names[idx]
#keep track of feature name and its corresponding score
score_vals.append(round(score, 3))
feature_vals.append(feature_names[idx])
#create a tuples of feature,score
#results = zip(feature_vals,score_vals)
results= {}
for idx in range(len(feature_vals)):
results[feature_vals[idx]]=score_vals[idx]
return results
feature_names=cv.get_feature_names()
doc=X[0]
tf_idf_vector=tfidf_transformer.transform(cv.transform([doc]))
sorted_items=sort_coo(tf_idf_vector.tocoo())
keywords=extract_topn_from_vector(feature_names,sorted_items,10)
print("\n=====Title=====")
print(X[0])
print("\n===Keywords===")
for k in keywords:
print(k,keywords[k])
【问题讨论】:
标签: python-3.x machine-learning word2vec pos-tagger tfidfvectorizer