anno/backends/
deberta_v3.rs1use crate::{Entity, EntityType, Model, Result};
23
24#[cfg(feature = "onnx")]
25use crate::backends::onnx::BertNEROnnx;
26
27pub struct DeBERTaV3NER {
32 #[cfg(feature = "onnx")]
33 inner: BertNEROnnx,
34 #[allow(dead_code)] model_name: String,
37}
38
39impl DeBERTaV3NER {
40 pub fn new(model_name: &str) -> Result<Self> {
45 #[cfg(feature = "onnx")]
46 {
47 let inner = BertNEROnnx::new(model_name)?;
49 Ok(Self {
50 inner,
51 model_name: model_name.to_string(),
52 })
53 }
54 #[cfg(not(feature = "onnx"))]
55 {
56 Err(crate::Error::FeatureNotAvailable(
57 "DeBERTa-v3 NER requires 'onnx' feature".to_string(),
58 ))
59 }
60 }
61}
62
63impl Model for DeBERTaV3NER {
64 fn extract_entities(&self, text: &str, language: Option<&str>) -> Result<Vec<Entity>> {
65 #[cfg(feature = "onnx")]
66 {
67 self.inner.extract_entities(text, language)
68 }
69 #[cfg(not(feature = "onnx"))]
70 {
71 Err(crate::Error::FeatureNotAvailable(
72 "DeBERTa-v3 NER requires 'onnx' feature".to_string(),
73 ))
74 }
75 }
76
77 fn supported_types(&self) -> Vec<EntityType> {
78 vec![
79 EntityType::Person,
80 EntityType::Organization,
81 EntityType::Location,
82 ]
83 }
84
85 fn is_available(&self) -> bool {
86 #[cfg(feature = "onnx")]
87 {
88 self.inner.is_available()
89 }
90 #[cfg(not(feature = "onnx"))]
91 {
92 false
93 }
94 }
95
96 fn name(&self) -> &'static str {
97 "deberta_v3"
98 }
99
100 fn description(&self) -> &'static str {
101 "DeBERTa-v3 NER with disentangled attention (wraps BERT ONNX backend)"
102 }
103
104 fn capabilities(&self) -> crate::ModelCapabilities {
105 crate::ModelCapabilities {
106 batch_capable: true,
107 streaming_capable: true,
108 ..Default::default()
109 }
110 }
111}
112
113impl crate::NamedEntityCapable for DeBERTaV3NER {}
114
115impl crate::BatchCapable for DeBERTaV3NER {
116 fn extract_entities_batch(
117 &self,
118 texts: &[&str],
119 language: Option<&str>,
120 ) -> Result<Vec<Vec<Entity>>> {
121 #[cfg(feature = "onnx")]
122 {
123 self.inner.extract_entities_batch(texts, language)
124 }
125 #[cfg(not(feature = "onnx"))]
126 {
127 Err(crate::Error::FeatureNotAvailable(
128 "DeBERTa-v3 NER requires 'onnx' feature".to_string(),
129 ))
130 }
131 }
132}
133
134impl crate::StreamingCapable for DeBERTaV3NER {
135 fn extract_entities_streaming(&self, chunk: &str, offset: usize) -> Result<Vec<Entity>> {
136 #[cfg(feature = "onnx")]
137 {
138 self.inner.extract_entities_streaming(chunk, offset)
139 }
140 #[cfg(not(feature = "onnx"))]
141 {
142 Err(crate::Error::FeatureNotAvailable(
143 "DeBERTa-v3 NER requires 'onnx' feature".to_string(),
144 ))
145 }
146 }
147}
148
149#[cfg(test)]
150mod tests {
151 use super::*;
152
153 #[test]
154 fn test_deberta_v3_name() {
155 if let Ok(model) = DeBERTaV3NER::new("microsoft/deberta-v3-base") {
156 assert_eq!(model.name(), "deberta_v3");
157 }
158 }
160}