pub struct NERModel { /* private fields */ }Expand description
Implementations§
source§impl NERModel
impl NERModel
sourcepub fn new(
ner_config: TokenClassificationConfig
) -> Result<NERModel, RustBertError>
pub fn new(
ner_config: TokenClassificationConfig
) -> Result<NERModel, RustBertError>
sourcepub fn predict<S>(&self, input: &[S]) -> Vec<Vec<Entity>> ⓘwhere
S: AsRef<str>,
pub fn predict<S>(&self, input: &[S]) -> Vec<Vec<Entity>> ⓘwhere
S: AsRef<str>,
Extract entities from a text
Arguments
input-&[&str]Array of texts to extract entities from.
Returns
Vec<Vec<Entity>>containing extracted entities
Example
let ner_model = NERModel::new(Default::default())?;
let input = [
"My name is Amy. I live in Paris.",
"Paris is a city in France.",
];
let output = ner_model.predict(&input);sourcepub fn predict_full_entities(&self, input: &[&str]) -> Vec<Vec<Entity>> ⓘ
pub fn predict_full_entities(&self, input: &[&str]) -> Vec<Vec<Entity>> ⓘ
Extract full entities from a text performing entity chunking. Follows the algorithm for entities chunking described in Erik F. Tjong Kim Sang, Jorn Veenstra, Representing Text Chunks The proposed implementation is inspired by the Python seqeval library (shared under MIT license).
Arguments
input-&[&str]Array of texts to extract entities from.
Returns
Vec<Entity>containing consolidated extracted entities
Example
let ner_model = NERModel::new(Default::default())?;
let input = ["Asked John Smith about Acme Corp"];
let output = ner_model.predict_full_entities(&input);Outputs:
Output:
[[
Entity {
word: String::from("John Smith"),
score: 0.9747,
label: String::from("PER"),
offset: Offset { begin: 6, end: 16 },
},
Entity {
word: String::from("Acme Corp"),
score: 0.8847,
label: String::from("I-LOC"),
offset: Offset { begin: 23, end: 32 },
},
]]