# Path: bertopic/backend/_base.py
# class BaseEmbedder:
#     """ The Base Embedder used for creating embedding models
# 
#     Arguments:
#         embedding_model: The main embedding model to be used for extracting
#                          document and word embedding
#         word_embedding_model: The embedding model used for extracting word
#                               embeddings only. If this model is selected,
#                               then the `embedding_model` is purely used for
#                               creating document embeddings.
#     """
#     def __init__(self,
#                  embedding_model=None,
#                  word_embedding_model=None):
#         self.embedding_model = embedding_model
#         self.word_embedding_model = word_embedding_model
# 
#     def embed(self,
#               documents: List[str],
#               verbose: bool = False) -> np.ndarray:
#         """ 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: Controls the verbosity of the process
# 
#         Returns:
#             Document/words embeddings with shape (n, m) with `n` documents/words
#             that each have an embeddings size of `m`
#         """
#         pass
# 
#     def embed_words(self,
#                     words: List[str],
#                     verbose: bool = False) -> np.ndarray:
#         """ Embed a list of n words into an n-dimensional
#         matrix of embeddings
# 
#         Arguments:
#             words: A list of words to be embedded
#             verbose: Controls the verbosity of the process
# 
#         Returns:
#             Word embeddings with shape (n, m) with `n` words
#             that each have an embeddings size of `m`
# 
#         """
#         return self.embed(words, verbose)
# 
#     def embed_documents(self,
#                         document: List[str],
#                         verbose: bool = False) -> np.ndarray:
#         """ Embed a list of n words into an n-dimensional
#         matrix of embeddings
# 
#         Arguments:
#             document: A list of documents to be embedded
#             verbose: Controls the verbosity of the process
# 
#         Returns:
#             Document embeddings with shape (n, m) with `n` documents
#             that each have an embeddings size of `m`
#         """
#         return self.embed(document, verbose)
# 
# Path: bertopic/backend/_utils.py
# def select_backend(embedding_model,
#                    language: str = None) -> BaseEmbedder:
#     """ Select an embedding model based on language or a specific sentence transformer models.
#     When selecting a language, we choose all-MiniLM-L6-v2 for English and
#     paraphrase-multilingual-MiniLM-L12-v2 for all other languages as it support 100+ languages.
# 
#     Returns:
#         model: Either a Sentence-Transformer or Flair model
#     """
#     # BERTopic language backend
#     if isinstance(embedding_model, BaseEmbedder):
#         return embedding_model
# 
#     # Flair word embeddings
#     if "flair" in str(type(embedding_model)):
#         from bertopic.backend._flair import FlairBackend
#         return FlairBackend(embedding_model)
# 
#     # Spacy embeddings
#     if "spacy" in str(type(embedding_model)):
#         from bertopic.backend._spacy import SpacyBackend
#         return SpacyBackend(embedding_model)
# 
#     # Gensim embeddings
#     if "gensim" in str(type(embedding_model)):
#         from bertopic.backend._gensim import GensimBackend
#         return GensimBackend(embedding_model)
# 
#     # USE embeddings
#     if "tensorflow" and "saved_model" in str(type(embedding_model)):
#         from bertopic.backend._use import USEBackend
#         return USEBackend(embedding_model)
# 
#     # Sentence Transformer embeddings
#     if "sentence_transformers" in str(type(embedding_model)):
#         return SentenceTransformerBackend(embedding_model)
# 
#     # Create a Sentence Transformer model based on a string
#     if isinstance(embedding_model, str):
#         return SentenceTransformerBackend(embedding_model)
# 
#     # Select embedding model based on language
#     if language:
#         if language.lower() in ["English", "english", "en"]:
#             return SentenceTransformerBackend("all-MiniLM-L6-v2")
#         elif language.lower() in languages or language == "multilingual":
#             return SentenceTransformerBackend("paraphrase-multilingual-MiniLM-L12-v2")
#         else:
#             raise ValueError(f"{language} is currently not supported. However, you can "
#                              f"create any embeddings yourself and pass it through fit_transform(docs, embeddings)\n"
#                              "Else, please select a language from the following list:\n"
#                              f"{languages}")
# 
#     return SentenceTransformerBackend("all-MiniLM-L6-v2")


import numpy as np
from typing import List
from bertopic.backend._base import BaseEmbedder
from bertopic.backend._utils import select_backend


class WordDocEmbedder(BaseEmbedder):
    """ Combine a document- and word-level embedder
    """
    def __init__(self,
                 embedding_model,
                 word_embedding_model):
        super().__init__()

        self.embedding_model = select_backend(embedding_model)

# Path: bertopic/backend/_base.py
# class BaseEmbedder:
#     """ The Base Embedder used for creating embedding models
# 
#     Arguments:
#         embedding_model: The main embedding model to be used for extracting
#                          document and word embedding
#         word_embedding_model: The embedding model used for extracting word
#                               embeddings only. If this model is selected,
#                               then the `embedding_model` is purely used for
#                               creating document embeddings.
#     """
#     def __init__(self,
#                  embedding_model=None,
#                  word_embedding_model=None):
#         self.embedding_model = embedding_model
#         self.word_embedding_model = word_embedding_model
# 
#     def embed(self,
#               documents: List[str],
#               verbose: bool = False) -> np.ndarray:
#         """ 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: Controls the verbosity of the process
# 
#         Returns:
#             Document/words embeddings with shape (n, m) with `n` documents/words
#             that each have an embeddings size of `m`
#         """
#         pass
# 
#     def embed_words(self,
#                     words: List[str],
#                     verbose: bool = False) -> np.ndarray:
#         """ Embed a list of n words into an n-dimensional
#         matrix of embeddings
# 
#         Arguments:
#             words: A list of words to be embedded
#             verbose: Controls the verbosity of the process
# 
#         Returns:
#             Word embeddings with shape (n, m) with `n` words
#             that each have an embeddings size of `m`
# 
#         """
#         return self.embed(words, verbose)
# 
#     def embed_documents(self,
#                         document: List[str],
#                         verbose: bool = False) -> np.ndarray:
#         """ Embed a list of n words into an n-dimensional
#         matrix of embeddings
# 
#         Arguments:
#             document: A list of documents to be embedded
#             verbose: Controls the verbosity of the process
# 
#         Returns:
#             Document embeddings with shape (n, m) with `n` documents
#             that each have an embeddings size of `m`
#         """
#         return self.embed(document, verbose)
# 
# Path: bertopic/backend/_utils.py
# def select_backend(embedding_model,
#                    language: str = None) -> BaseEmbedder:
#     """ Select an embedding model based on language or a specific sentence transformer models.
#     When selecting a language, we choose all-MiniLM-L6-v2 for English and
#     paraphrase-multilingual-MiniLM-L12-v2 for all other languages as it support 100+ languages.
# 
#     Returns:
#         model: Either a Sentence-Transformer or Flair model
#     """
#     # BERTopic language backend
#     if isinstance(embedding_model, BaseEmbedder):
#         return embedding_model
# 
#     # Flair word embeddings
#     if "flair" in str(type(embedding_model)):
#         from bertopic.backend._flair import FlairBackend
#         return FlairBackend(embedding_model)
# 
#     # Spacy embeddings
#     if "spacy" in str(type(embedding_model)):
#         from bertopic.backend._spacy import SpacyBackend
#         return SpacyBackend(embedding_model)
# 
#     # Gensim embeddings
#     if "gensim" in str(type(embedding_model)):
#         from bertopic.backend._gensim import GensimBackend
#         return GensimBackend(embedding_model)
# 
#     # USE embeddings
#     if "tensorflow" and "saved_model" in str(type(embedding_model)):
#         from bertopic.backend._use import USEBackend
#         return USEBackend(embedding_model)
# 
#     # Sentence Transformer embeddings
#     if "sentence_transformers" in str(type(embedding_model)):
#         return SentenceTransformerBackend(embedding_model)
# 
#     # Create a Sentence Transformer model based on a string
#     if isinstance(embedding_model, str):
#         return SentenceTransformerBackend(embedding_model)
# 
#     # Select embedding model based on language
#     if language:
#         if language.lower() in ["English", "english", "en"]:
#             return SentenceTransformerBackend("all-MiniLM-L6-v2")
#         elif language.lower() in languages or language == "multilingual":
#             return SentenceTransformerBackend("paraphrase-multilingual-MiniLM-L12-v2")
#         else:
#             raise ValueError(f"{language} is currently not supported. However, you can "
#                              f"create any embeddings yourself and pass it through fit_transform(docs, embeddings)\n"
#                              "Else, please select a language from the following list:\n"
#                              f"{languages}")
# 
#     return SentenceTransformerBackend("all-MiniLM-L6-v2")


# Path: bertopic/backend/_word_doc.py
import numpy as np
from typing import List
from bertopic.backend._base import BaseEmbedder
from bertopic.backend._utils import select_backend



class WordDocEmbedder(BaseEmbedder):
    """ Combine a document- and word-level embedder
    """
    def __init__(self,
                 embedding_model,
                 word_embedding_model):
        super().__init__()

        self.embedding_model = select_backend(embedding_model)

        self.word_embedding_model = select_backend(word_embedding_model)