Ich habe das Kapitel Von Strings zu Vektoren ausprobiert.
Der Stopplistenteil schließt unnötige Wörter aus.
Was ist ein Stoppwort? Wörter, die vom Suchziel ausgeschlossen werden müssen, um die Suchgenauigkeit zu verbessern, da zu viele Suchvorgänge erforderlich sind. Funktionswörter wie Hilfswörter und Hilfsverben (wie "ha", "no", "desu" und "masu" auf Japanisch und "the", "of", "is" auf Englisch) sind fast immer anwendbar. ..
sample.py
import logging
logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO)
from gensim import corpora, models, similarities
documents = ["Human machine interface for lab abc computer applications",
"A survey of user opinion of computer system response time",
"The EPS user interface management system",
"System and human system engineering testing of EPS",
"Relation of user perceived response time to error measurement",
"The generation of random binary unordered trees",
"The intersection graph of paths in trees",
"Graph minors IV Widths of trees and well quasi ordering",
"Graph minors A survey"]
# remove common words and tokenize
stoplist = set('for a of the and to in'.split())
texts = [[word for word in document.lower().split() if word not in stoplist]
for document in documents]
# remove words that appear only once
from collections import defaultdict
frequency = defaultdict(int)
# print(texts)
for text in texts:
for token in text:
frequency[token] += 1
texts = [[token for token in text if frequency[token] > 1]
for text in texts]
# from pprint import pprint # pretty-printer
# pprint(texts)
dictionary = corpora.Dictionary(texts)
# print(dictionary)
#Ausgabe mit id
# print(dictionary.token2id)
#In Satzvektor konvertieren
corpus = [dictionary.doc2bow(text) for text in texts]
print(corpus)
Offizielles Tutorial https://radimrehurek.com/gensim/tut1.html
Recommended Posts