human
I am working on the file "Gensim - Word2Vec.ipynb".
The first task is:
Build Doc2Vec Model from 2013 USPTO Patents
Can you write Python program for it?
 What is a the Python program you requested?
assistant
#Here is the Python program you requested.

from gensim.models.doc2vec import Doc2Vec, TaggedDocument

class PatentDocGenerator(object):
    def __init__(self, filename):
        self.filename = filename
        
    def __iter__(self):
        f = codecs.open(self.filename, 'r', 'UTF-8')
        for line in f:
            text, appnum = docs_out(line)
            yield TaggedDocument(text.split(), appnum.split())

model_d2v = Doc2Vec(size=200, window=8, sample=1e-5, hs=0, negative=5)
root = '/share/USPatentData/tokenized_appDate_2013/'

for fn in sorted(listdir(root)):
    doc = PatentDocGenerator(os.path.join(root, fn))
    start = dt.now()
    model_d2v.build_vocab(doc)
    model_d2v.train(doc)
    logging.info('{} training time: {}'.format(fn, str(dt.now() - start)))

model_d2v.save("doc2vec_uspto_2013.model")