This repository contains an easy and intuitive approach to few-shot NER using most similar expansion over spaCy embeddings.
Project description
Concise Concepts
When wanting to apply NER to concise concepts, it is really easy to come up with examples, but pretty difficult to train an entire pipeline. Concise Concepts uses few-shot NER based on word embedding similarity to get you going with easy!
Install
pip install concise-concepts
Quickstart
import spacy
from spacy import displacy
import concise_concepts
data = {
"fruit": ["apple", "pear", "orange"],
"vegetable": ["broccoli", "spinach", "tomato"],
"meat": ["beef", "pork", "fish", "lamb"]
}
text = """
Heat the oil in a large pan and add the Onion, celery and carrots.
Then, cook over a medium–low heat for 10 minutes, or until softened.
Add the courgette, garlic, red peppers and oregano and cook for 2–3 minutes.
Later, add some oranges and chickens. """
nlp = spacy.load("en_core_web_lg")
nlp.add_pipe("concise_concepts", config={"data": data})
doc = nlp(text)
options = {"colors": {"fruit": "darkorange", "vegetable": "limegreen", "meat": "salmon"},
"ents": ["fruit", "vegetable", "meat"]}
displacy.render(doc, style="ent", options=options)
use specific number of words to expand over
data = {
"fruit": ["apple", "pear", "orange"],
"vegetable": ["broccoli", "spinach", "tomato"],
"meat": ["beef", "pork", "fish", "lamb"]
}
topn = [50, 50, 150]
assert len(topn) == len
nlp.add_pipe("concise_concepts", config={"data": data, "topn": topn})
use gensim.word2vec model from pre-trained gensim or custom model path
data = {
"fruit": ["apple", "pear", "orange"],
"vegetable": ["broccoli", "spinach", "tomato"],
"meat": ["beef", "pork", "fish", "lamb"]
}
# model from https://radimrehurek.com/gensim/downloader.html or path to local file
model_path = "glove-twitter-25"
nlp.add_pipe("concise_concepts", config={"data": data, "model_path": model_path})
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
concise-concepts-0.3.0.tar.gz
(9.9 kB
view hashes)
Built Distribution
Close
Hashes for concise_concepts-0.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a5726379d65de2bf8915619c28ffc4d2f6f9512c3ab3bf303c78de023dcc7f6 |
|
MD5 | c5843f34f31a17b2c6cfd782bd646f68 |
|
BLAKE2b-256 | b74246aa50333132de2f3ee6a8415d46521b543bee1fd9af0df44f2d85d4cf52 |