mirror of
https://github.com/mii443/tokenizers.git
synced 2025-08-23 00:35:35 +00:00
Implement __new__ for PostProcessors
Allows PostProcessors to be instansiated through python class constructor.
This commit is contained in:
@ -8,31 +8,31 @@ pub struct PostProcessor {
|
||||
pub processor: Container<dyn tk::tokenizer::PostProcessor + Sync>,
|
||||
}
|
||||
|
||||
#[pyclass]
|
||||
#[pyclass(extends=PostProcessor)]
|
||||
pub struct BertProcessing {}
|
||||
#[pymethods]
|
||||
impl BertProcessing {
|
||||
#[staticmethod]
|
||||
fn new(sep: (String, u32), cls: (String, u32)) -> PyResult<PostProcessor> {
|
||||
Ok(PostProcessor {
|
||||
#[new]
|
||||
fn new(obj: &PyRawObject, sep: (String, u32), cls: (String, u32)) -> PyResult<()> {
|
||||
Ok(obj.init(PostProcessor {
|
||||
processor: Container::Owned(Box::new(tk::processors::bert::BertProcessing::new(
|
||||
sep, cls,
|
||||
))),
|
||||
})
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[pyclass]
|
||||
#[pyclass(extends=PostProcessor)]
|
||||
pub struct RobertaProcessing {}
|
||||
#[pymethods]
|
||||
impl RobertaProcessing {
|
||||
#[staticmethod]
|
||||
fn new(sep: (String, u32), cls: (String, u32)) -> PyResult<PostProcessor> {
|
||||
Ok(PostProcessor {
|
||||
#[new]
|
||||
fn new(obj: &PyRawObject, sep: (String, u32), cls: (String, u32)) -> PyResult<()> {
|
||||
Ok(obj.init(PostProcessor {
|
||||
processor: Container::Owned(Box::new(tk::processors::roberta::RobertaProcessing::new(
|
||||
sep, cls,
|
||||
))),
|
||||
})
|
||||
}))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user