
    Wi	                     6    d dl mZ d dlmZmZ  G d de      Zy)    )BaseEmbedder)check_is_fittedNotFittedErrorc                   *     e Zd ZdZ fdZddZ xZS )SklearnEmbeddera  Scikit-Learn based embedding model.

    This component allows the usage of scikit-learn pipelines for generating document and
    word embeddings.

    Arguments:
        pipe: A scikit-learn pipeline that can `.transform()` text.

    Examples:
    Scikit-Learn is very flexible and it allows for many representations.
    A relatively simple pipeline is shown below.

    ```python
    from sklearn.pipeline import make_pipeline
    from sklearn.decomposition import TruncatedSVD
    from sklearn.feature_extraction.text import TfidfVectorizer

    from bertopic.backend import SklearnEmbedder

    pipe = make_pipeline(
        TfidfVectorizer(),
        TruncatedSVD(100)
    )

    sklearn_embedder = SklearnEmbedder(pipe)
    topic_model = BERTopic(embedding_model=sklearn_embedder)
    ```

    This pipeline first constructs a sparse representation based on TF/idf and then
    makes it dense by applying SVD. Alternatively, you might also construct something
    more elaborate. As long as you construct a scikit-learn compatible pipeline, you
    should be able to pass it to Bertopic.

    !!! Warning
        One caveat to be aware of is that scikit-learns base `Pipeline` class does not
        support the `.partial_fit()`-API. If you have a pipeline that theoretically should
        be able to support online learning then you might want to explore
        the [scikit-partial](https://github.com/koaning/scikit-partial) project.
    c                 0    t         |           || _        y )N)super__init__pipe)selfr   	__class__s     e/home/sietch6/trending-topics-pipeline/venv/lib/python3.12/site-packages/bertopic/backend/_sklearn.pyr
   zSklearnEmbedder.__init__.   s    	    c                     	 t        | j                         | j                  j                  |      }|S # t        $ r | j                  j	                  |      }Y |S w xY w)a  Embed a list of n documents/words into an n-dimensional
        matrix of embeddings.

        Arguments:
            documents: A list of documents or words to be embedded
            verbose: No-op variable that's kept around to keep the API consistent. If you want to get feedback on training times, you should use the sklearn API.

        Returns:
            Document/words embeddings with shape (n, m) with `n` documents/words
            that each have an embeddings size of `m`
        )r   r   	transformr   fit_transform)r   	documentsverbose
embeddingss       r   embedzSklearnEmbedder.embed2   sZ    	<DII&,,Y7J   	<00;J	<s   04 $AA)F)__name__
__module____qualname____doc__r
   r   __classcell__)r   s   @r   r   r      s    &Pr   r   N)bertopic.backendr   sklearn.utils.validationr   r   r    r   r   <module>r      s    ) D?l ?r   