Repository: flairNLP/flair

Issue:
Mark DocumentMeanEmbedding as deprecated
https://github.com/zalandoresearch/flair/pull/191 introcuded `DocumentPoolEmbeddings`. Thus `DocumentMeanEmbeddings` are obsolete. They should be marked as `deprecated`.

Also update the tests to run at least some of the embeddings tests on travis (mark them as integration tests).


Discussion:

Resolving patch:
diff --git a/flair/embeddings.py b/flair/embeddings.py
--- a/flair/embeddings.py
+++ b/flair/embeddings.py
@@ -1,11 +1,12 @@
 import os
 import re
 from abc import abstractmethod
-from typing import List, Union, Dict, Tuple
+from typing import List, Union, Dict
 
 import gensim
 import numpy as np
 import torch
+from deprecated import deprecated
 
 from .nn import LockedDropout, WordDropout
 from .data import Dictionary, Token, Sentence
@@ -556,6 +557,7 @@ def _add_embeddings_internal(self, sentences: List[Sentence]) -> List[Sentence]:
 
 class DocumentMeanEmbeddings(DocumentEmbeddings):
 
+    @deprecated(version='0.3.1', reason="The functionality of this class is moved to 'DocumentPoolEmbeddings'")
     def __init__(self, token_embeddings: List[TokenEmbeddings]):
         """The constructor takes a list of embeddings to be combined."""
         super().__init__()


Test patch:
diff --git a/tests/test_embeddings.py b/tests/test_embeddings.py
--- a/tests/test_embeddings.py
+++ b/tests/test_embeddings.py
@@ -77,16 +77,11 @@ def test_german_backward():
     load_and_apply_char_lm_embeddings('german-backward')
 
 
-@pytest.mark.slow
+@pytest.mark.integration
 def test_stacked_embeddings():
-    text = 'I love Berlin.'
-    sentence: Sentence = Sentence(text)
-
-    glove: TokenEmbeddings = WordEmbeddings('en-glove')
-    news: TokenEmbeddings = WordEmbeddings('en-news')
-    charlm: TokenEmbeddings = CharLMEmbeddings('mix-backward')
+    sentence, glove, charlm = init_document_embeddings()
 
-    embeddings: StackedEmbeddings = StackedEmbeddings([glove, news, charlm])
+    embeddings: StackedEmbeddings = StackedEmbeddings([glove, charlm])
 
     embeddings.embed(sentence)
 
@@ -98,7 +93,7 @@ def test_stacked_embeddings():
         assert(len(token.get_embedding()) == 0)
 
 
-@pytest.mark.slow
+@pytest.mark.integration
 def test_document_lstm_embeddings():
     sentence, glove, charlm = init_document_embeddings()
 
@@ -115,7 +110,7 @@ def test_document_lstm_embeddings():
     assert (len(sentence.get_embedding()) == 0)
 
 
-@pytest.mark.slow
+@pytest.mark.integration
 def test_document_bidirectional_lstm_embeddings():
     sentence, glove, charlm = init_document_embeddings()
 
@@ -132,7 +127,7 @@ def test_document_bidirectional_lstm_embeddings():
     assert (len(sentence.get_embedding()) == 0)
 
 
-@pytest.mark.slow
+@pytest.mark.integration
 def test_document_bidirectional_lstm_embeddings_using_first_representation():
     sentence, glove, charlm = init_document_embeddings()
 
@@ -149,23 +144,6 @@ def test_document_bidirectional_lstm_embeddings_using_first_representation():
     assert (len(sentence.get_embedding()) == 0)
 
 
-@pytest.mark.slow
-def test_document_lstm_embeddings_using_first_representation():
-    sentence, glove, charlm = init_document_embeddings()
-
-    embeddings: DocumentLSTMEmbeddings = DocumentLSTMEmbeddings([glove, charlm], hidden_states=128,
-                                                                bidirectional=False)
-
-    embeddings.embed(sentence)
-
-    assert (len(sentence.get_embedding()) != 0)
-    assert (sentence.get_embedding().shape[1] == embeddings.embedding_length)
-
-    sentence.clear_embeddings()
-
-    assert (len(sentence.get_embedding()) == 0)
-
-
 @pytest.mark.slow
 def test_document_mean_embeddings():
     text = 'I love Berlin. Berlin is a great place to live.'
@@ -185,13 +163,9 @@ def test_document_mean_embeddings():
     assert (len(sentence.get_embedding()) == 0)
 
 
-@pytest.mark.skipif("TRAVIS" in os.environ and os.environ["TRAVIS"] == "true", reason="Skipping this test on Travis CI.")
+@pytest.mark.integration
 def test_document_pool_embeddings():
-    text = 'I love Berlin. Berlin is a great place to live.'
-    sentence: Sentence = Sentence(text)
-
-    glove: TokenEmbeddings = WordEmbeddings('en-glove')
-    charlm: TokenEmbeddings = CharLMEmbeddings('mix-backward')
+    sentence, glove, charlm = init_document_embeddings()
 
     for mode in ['mean', 'max', 'min']:
         embeddings: DocumentPoolEmbeddings = DocumentPoolEmbeddings([glove, charlm], mode=mode)
@@ -205,6 +179,16 @@ def test_document_pool_embeddings():
         assert (len(sentence.get_embedding()) == 0)
 
 
+def init_document_embeddings():
+    text = 'I love Berlin. Berlin is a great place to live.'
+    sentence: Sentence = Sentence(text)
+
+    glove: TokenEmbeddings = WordEmbeddings('en-glove')
+    charlm: TokenEmbeddings = CharLMEmbeddings('news-forward-fast')
+
+    return sentence, glove, charlm
+
+
 def load_and_apply_word_embeddings(emb_type: str):
     text = 'I love Berlin.'
     sentence: Sentence = Sentence(text)