prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  D2VTransformer.fit_transform doesn't work
  The **X** parameter of the **fit_transform** method of **D2VTransformer** doesn't accept variables of any type, nor list of token lists (raises _AttributeError: 'list' object has no attribute 'words'_), nor list of TaggedDocument (raises _TypeError: sequence item 0: expected str instance, list found_).
  
  Example:
  ```python
  from gensim.sklearn_api import D2VTransformer
  from gensim.models import doc2vec
  
  class_dict = {'mathematics': 1, 'physics': 0}
  train_data = [
      (['calculus', 'mathematical'], 'mathematics'), (['geometry', 'operations', 'curves'], 'mathematics'),
      (['natural', 'nuclear'], 'physics'), (['science', 'electromagnetism', 'natural'], 'physics')
  ]
  d2v_sentences = [doc2vec.TaggedDocument(words[0], [i]) for i, words in enumerate(train_data)]
  train_input = list(map(lambda x: x[0], train_data))
  train_target = list(map(lambda x: class_dict[x[1]], train_data))
  
  model = D2VTransformer(min_count=1)
  model.fit_transform(train_input, train_target)
  #model.fit_transform(d2v_sentences, train_target)
  ```
  Versions:
  Windows-10-10.0.16299-SP0
  Python 3.6.4 | packaged by conda-forge | (default, Dec 24 2017, 10:11:43) [MSC v.1900 64 bit (AMD64)]
  NumPy 1.13.3
  SciPy 0.19.1
  gensim 3.2.0
  FAST_VERSION 1
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `gensim/sklearn_api/d2vmodel.py`
  Content:
  ```
  1 #!/usr/bin/env python
  2 # -*- coding: utf-8 -*-
  3 #
  4 # Copyright (C) 2011 Radim Rehurek <radimrehurek@seznam.cz>
  5 # Licensed under the GNU LGPL v2.1 - http://www.gnu.org/licenses/lgpl.html
  6 
  7 """
  8 Scikit learn interface for gensim for easy use of gensim with scikit-learn
  9 Follows scikit-learn API conventions
  10 """
  11 
  12 import numpy as np
  13 from six import string_types
  14 from sklearn.base import TransformerMixin, BaseEstimator
  15 from sklearn.exceptions import NotFittedError
  16 
  17 from gensim import models
  18 
  19 
  20 class D2VTransformer(TransformerMixin, BaseEstimator):
  21     """
  22     Base Doc2Vec module
  23     """
  24 
  25     def __init__(self, dm_mean=None, dm=1, dbow_words=0, dm_concat=0, dm_tag_count=1, docvecs=None,
  26                  docvecs_mapfile=None, comment=None, trim_rule=None, size=100, alpha=0.025, window=5, min_count=5,
  27                  max_vocab_size=None, sample=1e-3, seed=1, workers=3, min_alpha=0.0001, hs=0, negative=5, cbow_mean=1,
  28                  hashfxn=hash, iter=5, sorted_vocab=1, batch_words=10000):
  29         """
  30         Sklearn api for Doc2Vec model. See gensim.models.Doc2Vec and gensim.models.Word2Vec for parameter details.
  31         """
  32         self.gensim_model = None
  33         self.dm_mean = dm_mean
  34         self.dm = dm
  35         self.dbow_words = dbow_words
  36         self.dm_concat = dm_concat
  37         self.dm_tag_count = dm_tag_count
  38         self.docvecs = docvecs
  39         self.docvecs_mapfile = docvecs_mapfile
  40         self.comment = comment
  41         self.trim_rule = trim_rule
  42 
  43         # attributes associated with gensim.models.Word2Vec
  44         self.size = size
  45         self.alpha = alpha
  46         self.window = window
  47         self.min_count = min_count
  48         self.max_vocab_size = max_vocab_size
  49         self.sample = sample
  50         self.seed = seed
  51         self.workers = workers
  52         self.min_alpha = min_alpha
  53         self.hs = hs
  54         self.negative = negative
  55         self.cbow_mean = int(cbow_mean)
  56         self.hashfxn = hashfxn
  57         self.iter = iter
  58         self.sorted_vocab = sorted_vocab
  59         self.batch_words = batch_words
  60 
  61     def fit(self, X, y=None):
  62         """
  63         Fit the model according to the given training data.
  64         Calls gensim.models.Doc2Vec
  65         """
  66         self.gensim_model = models.Doc2Vec(
  67             documents=X, dm_mean=self.dm_mean, dm=self.dm,
  68             dbow_words=self.dbow_words, dm_concat=self.dm_concat, dm_tag_count=self.dm_tag_count,
  69             docvecs=self.docvecs, docvecs_mapfile=self.docvecs_mapfile, comment=self.comment,
  70             trim_rule=self.trim_rule, size=self.size, alpha=self.alpha, window=self.window,
  71             min_count=self.min_count, max_vocab_size=self.max_vocab_size, sample=self.sample,
  72             seed=self.seed, workers=self.workers, min_alpha=self.min_alpha, hs=self.hs,
  73             negative=self.negative, cbow_mean=self.cbow_mean, hashfxn=self.hashfxn,
  74             iter=self.iter, sorted_vocab=self.sorted_vocab, batch_words=self.batch_words
  75         )
  76         return self
  77 
  78     def transform(self, docs):
  79         """
  80         Return the vector representations for the input documents.
  81         The input `docs` should be a list of lists like
  82         [['calculus', 'mathematical'],
  83         ['geometry', 'operations', 'curves']]
  84         or a single document like : ['calculus', 'mathematical']
  85         """
  86         if self.gensim_model is None:
  87             raise NotFittedError(
  88                 "This model has not been fitted yet. Call 'fit' with appropriate arguments before using this method."
  89             )
  90 
  91         # The input as array of array
  92         if isinstance(docs[0], string_types):
  93             docs = [docs]
  94         vectors = [self.gensim_model.infer_vector(doc) for doc in docs]
  95         return np.reshape(np.array(vectors), (len(docs), self.gensim_model.vector_size))
  96
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/gensim/sklearn_api/d2vmodel.py b/gensim/sklearn_api/d2vmodel.py
  --- a/gensim/sklearn_api/d2vmodel.py
  +++ b/gensim/sklearn_api/d2vmodel.py
  @@ -15,6 +15,7 @@
   from sklearn.exceptions import NotFittedError
   
   from gensim import models
  +from gensim.models import doc2vec
   
   
   class D2VTransformer(TransformerMixin, BaseEstimator):
  @@ -63,8 +64,12 @@
           Fit the model according to the given training data.
           Calls gensim.models.Doc2Vec
           """
  +        if isinstance(X[0], doc2vec.TaggedDocument):
  +            d2v_sentences = X
  +        else:
  +            d2v_sentences = [doc2vec.TaggedDocument(words, [i]) for i, words in enumerate(X)]
           self.gensim_model = models.Doc2Vec(
  -            documents=X, dm_mean=self.dm_mean, dm=self.dm,
  +            documents=d2v_sentences, dm_mean=self.dm_mean, dm=self.dm,
               dbow_words=self.dbow_words, dm_concat=self.dm_concat, dm_tag_count=self.dm_tag_count,
               docvecs=self.docvecs, docvecs_mapfile=self.docvecs_mapfile, comment=self.comment,
               trim_rule=self.trim_rule, size=self.size, alpha=self.alpha, window=self.window,
  
verification_info: {"golden_diff": "diff --git a/gensim/sklearn_api/d2vmodel.py b/gensim/sklearn_api/d2vmodel.py\n--- a/gensim/sklearn_api/d2vmodel.py\n+++ b/gensim/sklearn_api/d2vmodel.py\n@@ -15,6 +15,7 @@\n from sklearn.exceptions import NotFittedError\n \n from gensim import models\n+from gensim.models import doc2vec\n \n \n class D2VTransformer(TransformerMixin, BaseEstimator):\n@@ -63,8 +64,12 @@\n         Fit the model according to the given training data.\n         Calls gensim.models.Doc2Vec\n         \"\"\"\n+        if isinstance(X[0], doc2vec.TaggedDocument):\n+            d2v_sentences = X\n+        else:\n+            d2v_sentences = [doc2vec.TaggedDocument(words, [i]) for i, words in enumerate(X)]\n         self.gensim_model = models.Doc2Vec(\n-            documents=X, dm_mean=self.dm_mean, dm=self.dm,\n+            documents=d2v_sentences, dm_mean=self.dm_mean, dm=self.dm,\n             dbow_words=self.dbow_words, dm_concat=self.dm_concat, dm_tag_count=self.dm_tag_count,\n             docvecs=self.docvecs, docvecs_mapfile=self.docvecs_mapfile, comment=self.comment,\n             trim_rule=self.trim_rule, size=self.size, alpha=self.alpha, window=self.window,\n", "issue": "D2VTransformer.fit_transform doesn't work\nThe **X** parameter of the **fit_transform** method of **D2VTransformer** doesn't accept variables of any type, nor list of token lists (raises _AttributeError: 'list' object has no attribute 'words'_), nor list of TaggedDocument (raises _TypeError: sequence item 0: expected str instance, list found_).\r\n\r\nExample:\r\n```python\r\nfrom gensim.sklearn_api import D2VTransformer\r\nfrom gensim.models import doc2vec\r\n\r\nclass_dict = {'mathematics': 1, 'physics': 0}\r\ntrain_data = [\r\n    (['calculus', 'mathematical'], 'mathematics'), (['geometry', 'operations', 'curves'], 'mathematics'),\r\n    (['natural', 'nuclear'], 'physics'), (['science', 'electromagnetism', 'natural'], 'physics')\r\n]\r\nd2v_sentences = [doc2vec.TaggedDocument(words[0], [i]) for i, words in enumerate(train_data)]\r\ntrain_input = list(map(lambda x: x[0], train_data))\r\ntrain_target = list(map(lambda x: class_dict[x[1]], train_data))\r\n\r\nmodel = D2VTransformer(min_count=1)\r\nmodel.fit_transform(train_input, train_target)\r\n#model.fit_transform(d2v_sentences, train_target)\r\n```\r\nVersions:\r\nWindows-10-10.0.16299-SP0\r\nPython 3.6.4 | packaged by conda-forge | (default, Dec 24 2017, 10:11:43) [MSC v.1900 64 bit (AMD64)]\r\nNumPy 1.13.3\r\nSciPy 0.19.1\r\ngensim 3.2.0\r\nFAST_VERSION 1\n", "before_files": [{"content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n#\n# Copyright (C) 2011 Radim Rehurek <radimrehurek@seznam.cz>\n# Licensed under the GNU LGPL v2.1 - http://www.gnu.org/licenses/lgpl.html\n\n\"\"\"\nScikit learn interface for gensim for easy use of gensim with scikit-learn\nFollows scikit-learn API conventions\n\"\"\"\n\nimport numpy as np\nfrom six import string_types\nfrom sklearn.base import TransformerMixin, BaseEstimator\nfrom sklearn.exceptions import NotFittedError\n\nfrom gensim import models\n\n\nclass D2VTransformer(TransformerMixin, BaseEstimator):\n    \"\"\"\n    Base Doc2Vec module\n    \"\"\"\n\n    def __init__(self, dm_mean=None, dm=1, dbow_words=0, dm_concat=0, dm_tag_count=1, docvecs=None,\n                 docvecs_mapfile=None, comment=None, trim_rule=None, size=100, alpha=0.025, window=5, min_count=5,\n                 max_vocab_size=None, sample=1e-3, seed=1, workers=3, min_alpha=0.0001, hs=0, negative=5, cbow_mean=1,\n                 hashfxn=hash, iter=5, sorted_vocab=1, batch_words=10000):\n        \"\"\"\n        Sklearn api for Doc2Vec model. See gensim.models.Doc2Vec and gensim.models.Word2Vec for parameter details.\n        \"\"\"\n        self.gensim_model = None\n        self.dm_mean = dm_mean\n        self.dm = dm\n        self.dbow_words = dbow_words\n        self.dm_concat = dm_concat\n        self.dm_tag_count = dm_tag_count\n        self.docvecs = docvecs\n        self.docvecs_mapfile = docvecs_mapfile\n        self.comment = comment\n        self.trim_rule = trim_rule\n\n        # attributes associated with gensim.models.Word2Vec\n        self.size = size\n        self.alpha = alpha\n        self.window = window\n        self.min_count = min_count\n        self.max_vocab_size = max_vocab_size\n        self.sample = sample\n        self.seed = seed\n        self.workers = workers\n        self.min_alpha = min_alpha\n        self.hs = hs\n        self.negative = negative\n        self.cbow_mean = int(cbow_mean)\n        self.hashfxn = hashfxn\n        self.iter = iter\n        self.sorted_vocab = sorted_vocab\n        self.batch_words = batch_words\n\n    def fit(self, X, y=None):\n        \"\"\"\n        Fit the model according to the given training data.\n        Calls gensim.models.Doc2Vec\n        \"\"\"\n        self.gensim_model = models.Doc2Vec(\n            documents=X, dm_mean=self.dm_mean, dm=self.dm,\n            dbow_words=self.dbow_words, dm_concat=self.dm_concat, dm_tag_count=self.dm_tag_count,\n            docvecs=self.docvecs, docvecs_mapfile=self.docvecs_mapfile, comment=self.comment,\n            trim_rule=self.trim_rule, size=self.size, alpha=self.alpha, window=self.window,\n            min_count=self.min_count, max_vocab_size=self.max_vocab_size, sample=self.sample,\n            seed=self.seed, workers=self.workers, min_alpha=self.min_alpha, hs=self.hs,\n            negative=self.negative, cbow_mean=self.cbow_mean, hashfxn=self.hashfxn,\n            iter=self.iter, sorted_vocab=self.sorted_vocab, batch_words=self.batch_words\n        )\n        return self\n\n    def transform(self, docs):\n        \"\"\"\n        Return the vector representations for the input documents.\n        The input `docs` should be a list of lists like\n        [['calculus', 'mathematical'],\n        ['geometry', 'operations', 'curves']]\n        or a single document like : ['calculus', 'mathematical']\n        \"\"\"\n        if self.gensim_model is None:\n            raise NotFittedError(\n                \"This model has not been fitted yet. Call 'fit' with appropriate arguments before using this method.\"\n            )\n\n        # The input as array of array\n        if isinstance(docs[0], string_types):\n            docs = [docs]\n        vectors = [self.gensim_model.infer_vector(doc) for doc in docs]\n        return np.reshape(np.array(vectors), (len(docs), self.gensim_model.vector_size))\n", "path": "gensim/sklearn_api/d2vmodel.py"}], "after_files": [{"content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n#\n# Copyright (C) 2011 Radim Rehurek <radimrehurek@seznam.cz>\n# Licensed under the GNU LGPL v2.1 - http://www.gnu.org/licenses/lgpl.html\n\n\"\"\"\nScikit learn interface for gensim for easy use of gensim with scikit-learn\nFollows scikit-learn API conventions\n\"\"\"\n\nimport numpy as np\nfrom six import string_types\nfrom sklearn.base import TransformerMixin, BaseEstimator\nfrom sklearn.exceptions import NotFittedError\n\nfrom gensim import models\nfrom gensim.models import doc2vec\n\n\nclass D2VTransformer(TransformerMixin, BaseEstimator):\n    \"\"\"\n    Base Doc2Vec module\n    \"\"\"\n\n    def __init__(self, dm_mean=None, dm=1, dbow_words=0, dm_concat=0, dm_tag_count=1, docvecs=None,\n                 docvecs_mapfile=None, comment=None, trim_rule=None, size=100, alpha=0.025, window=5, min_count=5,\n                 max_vocab_size=None, sample=1e-3, seed=1, workers=3, min_alpha=0.0001, hs=0, negative=5, cbow_mean=1,\n                 hashfxn=hash, iter=5, sorted_vocab=1, batch_words=10000):\n        \"\"\"\n        Sklearn api for Doc2Vec model. See gensim.models.Doc2Vec and gensim.models.Word2Vec for parameter details.\n        \"\"\"\n        self.gensim_model = None\n        self.dm_mean = dm_mean\n        self.dm = dm\n        self.dbow_words = dbow_words\n        self.dm_concat = dm_concat\n        self.dm_tag_count = dm_tag_count\n        self.docvecs = docvecs\n        self.docvecs_mapfile = docvecs_mapfile\n        self.comment = comment\n        self.trim_rule = trim_rule\n\n        # attributes associated with gensim.models.Word2Vec\n        self.size = size\n        self.alpha = alpha\n        self.window = window\n        self.min_count = min_count\n        self.max_vocab_size = max_vocab_size\n        self.sample = sample\n        self.seed = seed\n        self.workers = workers\n        self.min_alpha = min_alpha\n        self.hs = hs\n        self.negative = negative\n        self.cbow_mean = int(cbow_mean)\n        self.hashfxn = hashfxn\n        self.iter = iter\n        self.sorted_vocab = sorted_vocab\n        self.batch_words = batch_words\n\n    def fit(self, X, y=None):\n        \"\"\"\n        Fit the model according to the given training data.\n        Calls gensim.models.Doc2Vec\n        \"\"\"\n        if isinstance(X[0], doc2vec.TaggedDocument):\n            d2v_sentences = X\n        else:\n            d2v_sentences = [doc2vec.TaggedDocument(words, [i]) for i, words in enumerate(X)]\n        self.gensim_model = models.Doc2Vec(\n            documents=d2v_sentences, dm_mean=self.dm_mean, dm=self.dm,\n            dbow_words=self.dbow_words, dm_concat=self.dm_concat, dm_tag_count=self.dm_tag_count,\n            docvecs=self.docvecs, docvecs_mapfile=self.docvecs_mapfile, comment=self.comment,\n            trim_rule=self.trim_rule, size=self.size, alpha=self.alpha, window=self.window,\n            min_count=self.min_count, max_vocab_size=self.max_vocab_size, sample=self.sample,\n            seed=self.seed, workers=self.workers, min_alpha=self.min_alpha, hs=self.hs,\n            negative=self.negative, cbow_mean=self.cbow_mean, hashfxn=self.hashfxn,\n            iter=self.iter, sorted_vocab=self.sorted_vocab, batch_words=self.batch_words\n        )\n        return self\n\n    def transform(self, docs):\n        \"\"\"\n        Return the vector representations for the input documents.\n        The input `docs` should be a list of lists like\n        [['calculus', 'mathematical'],\n        ['geometry', 'operations', 'curves']]\n        or a single document like : ['calculus', 'mathematical']\n        \"\"\"\n        if self.gensim_model is None:\n            raise NotFittedError(\n                \"This model has not been fitted yet. Call 'fit' with appropriate arguments before using this method.\"\n            )\n\n        # The input as array of array\n        if isinstance(docs[0], string_types):\n            docs = [docs]\n        vectors = [self.gensim_model.infer_vector(doc) for doc in docs]\n        return np.reshape(np.array(vectors), (len(docs), self.gensim_model.vector_size))\n", "path": "gensim/sklearn_api/d2vmodel.py"}]}