# Buggy code
def _add_embeddings_internal(self, sentences: List[Sentence]) -> List[Sentence]:
    for i, sentence in enumerate(sentences):
        language_code = sentence.get_language_code()
        supported = [
            "en",
            "de",
            "bg",
            "ca",
            "hr",
            "cs",
            "da",
            "nl",
            "et",
            "fi",
            "fr",
            "el",
            "he",
            "hu",
            "id",
            "it",
            "mk",
            "no",
            "pl",
            "pt",
            "ro",
            "ru",
            "sk",
        ]
        if language_code not in supported:
            language_code = "en"

        if language_code not in self.language_embeddings:
            log.info(f"Loading up MUSE embeddings for '{language_code}'!")
            # download if necessary
            webpath = "https://alan-nlp.s3.eu-central-1.amazonaws.com/resources/embeddings-muse"
            cache_dir = Path("embeddings") / "MUSE"
            cached_path(
                f"{webpath}/muse.{language_code}.vec.gensim.vectors.npy",
                cache_dir=cache_dir,
            )
            embeddings_file = cached_path(
                f"{webpath}/muse.{language_code}.vec.gensim", cache_dir=cache_dir
            )

            # load the model
            self.language_embeddings[language_code] = gensim.models.KeyedVectors.load(
                str(embeddings_file)
            )

        for token, token_idx in zip(sentence.tokens, range(len(sentence.tokens))):
            if "field" not in self.__dict__ or self.field is None:
                word = token.text
            else:
                word = token.get_tag(self.field).value

            word_embedding = self.get_cached_vec(language_code=language_code, word=word)

            token.set_embedding(self.name, word_embedding)

    return sentences


# Traceback (AttributeError)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-26-1ee39d7138b3> in <module>()
----> 1 df_test['flair'] = df_test['word'].apply(lambda x: flair_lstm(x))

10 frames
pandas/_libs/lib.pyx in pandas._libs.lib.map_infer()

/usr/local/lib/python3.6/dist-packages/transformers/configuration_utils.py in use_return_dict(self)
217         """
218         # If torchscript is set, force `return_dict=False` to avoid jit errors
--> 219         return self.return_dict and not self.torchscript
220
221     @property

AttributeError: 'DistilBertConfig' object has no attribute 'return_dict'

# Fixed code
def _add_embeddings_internal(self, sentences: List[Sentence]) -> List[Sentence]:
    for i, sentence in enumerate(sentences):
        language_code = sentence.get_language_code()
        supported = [
            "en",
            "de",
            "bg",
            "ca",
            "hr",
            "cs",
            "da",
            "nl",
            "et",
            "fi",
            "fr",
            "el",
            "he",
            "hu",
            "id",
            "it",
            "mk",
            "no",
            "pl",
            "pt",
            "ro",
            "ru",
            "sk",
        ]
        if language_code not in supported:
            language_code = "en"

        if language_code not in self.language_embeddings:
            log.info(f"Loading up MUSE embeddings for '{language_code}'!")
            # download if necessary
            hu_path: str = (
                "https://flair.informatik.hu-berlin.de/resources/embeddings/muse"
            )
            cache_dir = Path("embeddings") / "MUSE"
            cached_path(
                f"{hu_path}/muse.{language_code}.vec.gensim.vectors.npy",
                cache_dir=cache_dir,
            )
            embeddings_file = cached_path(
                f"{hu_path}/muse.{language_code}.vec.gensim", cache_dir=cache_dir
            )

            # load the model
            self.language_embeddings[language_code] = gensim.models.KeyedVectors.load(
                str(embeddings_file)
            )

        for token, token_idx in zip(sentence.tokens, range(len(sentence.tokens))):
            if "field" not in self.__dict__ or self.field is None:
                word = token.text
            else:
                word = token.get_tag(self.field).value

            word_embedding = self.get_cached_vec(language_code=language_code, word=word)

            token.set_embedding(self.name, word_embedding)

    return sentences