ฉันใช้ sk-learn ใน python เพื่อให้พอดีกับโมเดลและแปลง input_data ผ่านโมเดล
ฉันใช้ FeatureUnion เพื่อรวม CountVectorizer และ TfidfEmbeddingVectorizer
คุณสามารถใช้เฉพาะ CountVectorizer หรือ TfidfEmbeddingVectorizer เท่านั้นก็ได้ แต่หากฉันรวมคุณสมบัติทั้งสองเข้าด้วยกันด้วย Feature Union จะมีข้อผิดพลาดดังนี้:
TypeError: fit() takes 2 positional arguments but 3 were given
คลาส TfidfEmbeddingVectorizer เป็นเช่นนี้:
class TfidfEmbeddingVectorizer(object):
...
def fit(self, X):
tfidf = TfidfVectorizer(analyzer=lambda x: x)
tfidf.fit(X)
# if a word was never seen - it must be at least as infrequent
# as any of the known words - so the default idf is the max of
# known idf's
max_idf = max(tfidf.idf_)
self.word2weight = defaultdict(
lambda: max_idf,
[(w, tfidf.idf_[i]) for w, i in tfidf.vocabulary_.items()])
return self
และฉันใช้ FeatureUnion เช่นนี้:
model = gensim.models.Word2Vec(speech.train_data, size = 100)
w2v = dict(zip(model.wv.index2word, model.wv.syn0))
count = CountVectorizer(tokenizer=lambda doc: doc, lowercase=False)
w2v_tfidf = TfidfEmbeddingVectorizer(w2v)
feature_union = FeatureUnion([('ngram', count),
('tfidf', w2v_tfidf)])
feature_union.fit(speech.train_data)
ฉันได้เห็นวิธีแก้ปัญหาที่การลดระดับเวอร์ชัน sk-learn เป็น 0.18.0 ทำให้เป็นเรื่องปกติ แต่ฉันไม่สามารถดาวน์เกรด sk-learn ด้วยข้อผิดพลาดนี้:
error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://andinghub.visualstudio.com/visual-cpp-build-tools
มีวิธีแก้ไขปัญหาอื่นสำหรับการใช้ฟังก์ชัน fit ของ FeatureUnion หรือไม่