fasttext-embeddings-with-flair

To get a better overview and understanding of the need for this project, I would recommend to read my article on the same.
The objective of this script is to be able to use our custom fasttext embeddings with the Flair.
The integration is very simple:
Copy the fasttext_custom_embeddings_with_flair.py file to your project.
Install the packages from requirements.txt.
Import the FastTextEmbeddings from fasttext_custom_embeddings_with_flair.py file.
Instantiate an object of FastTextEmbeddings by passing either the local path or the remote http(s) url to the constructor.
Use it like you use any other embedding object in Flair.
from fasttext_custom_embeddings_with_flair import FastTextEmbeddings from flair.data import Sentence
ft_embeddings = FastTextEmbeddings('/path/to/custom_fasttext_embeddings.bin', use_local=True)
sentence = Sentence('The quick brown fox jumps over a lazy dog.', use_tokenizer=True) 'ft_embeddings.embed(sentence)Initialize the constructor by passing the local path to embeddings .bin file.
Set the boolean use_local to True.
Support for embedding file with ".vec" extension is also added. We need to add one more parameter extension='.vec' to the constructor.
ft_embeddings = FastTextEmbeddings('/path/to/custom_fasttext_embeddings.vec', use_local=True, extension='.vec')Note: The ".vec" extension files do not support out of vocabulary(OOV) embeddings. In this case, for OOV words, zero vectors are assigned by default.
from fasttext_custom_embeddings_with_flair import FastTextEmbeddings
from flair.data import Sentence
ft_embeddings = FastTextEmbeddings('/url/to/custom_fattext_embeddings.bin', use_local=False)
sentence = Sentence('The quick brown fox jumps over a lazy dog.', use_tokenizer=True)
ft_embeddings.embed(sentence)Initialize the constructor by passing the remote url to embeddings .bin file. (I have tested this with my embeddings in S3 with an https url.)
Set the boolean use_local to False. (Mandatory step if you are using a remote url.)
from fasttext_custom_embeddings_with_flair import FastTextEmbeddings
from flair.embeddings import WordEmbeddings, StackedEmbeddingsfrom flair.data import Sentence
ft_embeddings = FastTextEmbeddings('/url/to/custom_fattext_embeddings.bin', use_local=False)
glove_embeddings = WordEmbeddings('glove')
stacked_embeddings = StackedEmbeddings([ft_embeddings, glove_embeddings])
sentence = Sentence('The quick brown fox jumps over a lazy dog.', use_tokenizer=True)
stacked_embeddings.embed(sentence)from fasttext_custom_embeddings_with_flair import FastTextEmbeddings
from flair.embeddings import WordEmbeddings, DocumentRNNEmbeddings
from flair.data import Sentence
ft_embeddings = FastTextEmbeddings('/url/to/custom_fattext_embeddings.bin', use_local=True)
glove_embeddings = WordEmbeddings('glove')
document_rnn_embeddings = DocumentRNNEmbeddings([ft_embeddings, glove_embeddings])
sentence = Sentence('The quick brown fox jumps over a lazy dog.', use_tokenizer=True)
document_rnn_embeddings.embed(sentence)In case of any doubts, get in touch.
Author: Pranay Chandekar
Refernces:
This repository is licensed under the Apache 2.0 License.
下一篇:Flair-JSON-NLP
还没有评论,说两句吧!
热门资源
TensorFlow-Course
This repository aims to provide simple and read...
DuReader_QANet_BiDAF
Machine Reading Comprehension on DuReader Usin...
My_DrQA
My_DrQA A re-implement DrQA based on Pytorch
Klukshu-Sockeye-...
KLUKSHU SOCKEYE PROJECTS 2016 This repositor...
flaireWebSite
flaireWebSite
智能在线
400-630-6780
聆听.建议反馈
E-mail: support@tusaishared.com