Created
June 11, 2017 14:11
-
-
Save justindavies/b343d44ec536d2e99e26019039201347 to your computer and use it in GitHub Desktop.
Doc2Vec Iterator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from gensim.models.doc2vec import LabeledSentence | |
import re | |
class DocIterator(object): | |
def __init__(self, doc_list, labels_list): | |
self.labels_list = labels_list | |
self.doc_list = doc_list | |
def __iter__(self): | |
for idx, doc in enumerate(self.doc_list): | |
yield LabeledSentence(words=doc.split(),tags=[self.labels_list[idx]]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment