* Properly handle config errors when creating classification models
Instead of panic, we now return a proper RustBertError so that
an invalid model or config thereof wouldn't crash the whole system.
* Properly formats newly added code.
* Fixes an example within the documentation
* Properly unwraps the newly created results in unit tests.
* Fixes some code formatting issues.
* Uses proper/idiomatic error handling in unit tests.
* Moves the "?" to the correct position.
* - Fixed Clippy warnings
- Updated `tch` dependency
- Updated README to avoid confusion with respect to the required `LIBTORCH` version for the repository and published package versions
* Fixed Clippy warnings (2)
* Fixed Clippy warnings (3)
* ad support for loading local moddel in SequenceClassificationConfig
* adjust config to match the SequenceClassificationConfig
* add piplines::masked_language
* add support and example for codebert
* provide an optional mask_token String field for asked_language pipline
* update example for masked_language pipeline
* codebert support revocation
* revoke support for loading local moddel
* solve conflicts
* update MaskedLanguageConfig
* fix doctest error in zero_shot_classification.rs
* MaskedLM pipeline updates
* fix multiple masked token, added test
* Updated changelog and docs
Co-authored-by: Guillaume Becquin <guillaume.becquin@gmail.com>
* Add checked prediction methods
- Add checked prediction methods to ZeroShotClassificationModel.
These methods return Option and convert any underlying errors into None,
to allow callers to implement appropriate error handling logic.
* Update ZeroShot example to use checked method.
* Add tests for ZeroShot checked methods
* Change checked prediction methods to return Result
* refactor: rename *_checked into try_*
Rename *_checked methods into try_* methods.
This is more idiomatic vis-a-vis the Rust standard library.
* refactor: remove try_ prefix from predict methods
* refactor: change return from Option to Result
Change return type of ZeroShotClassificationModel.prepare_for_model
from option into Result. This simplifies the code, and returns
the error closer to its origin.
This addresses comments from @guillaume-be.
* refactor: address clippy lints in tests
Co-authored-by: guillaume-be <guillaume.becquin@gmail.com>
* - made `merges` resource optional for all pipelines
- allow mixing local and remote resources for pipelines
* Updated changelog
* Fixed Clippy warnings
* Use `resize` instead of `append` to pad features
**This Commit**
Updates various instances of `append(&mut vec![...])` with
`resize(...)`.
**Why?**
As a micro optimization. I don't expect this to affect any benchmarks
since the change will be so small compared to the time it takes the
model to do anything but I ran a small benchmark and this seemed to be
the fastest way to do this because (I think):
- we allocate each attention mask exactly once to the correct capacity
- we don't allocate a new vector to append to the existing one[^1]
And, while this won't speed up anything in practice, I think it might
read more clearly since `resize` tells you the final length so we can
see that all the vectors are the same final length and match `max_len`.
<details>
<summary>Micro benchmark run</summary>
The rust code was roughly:
```rust
pub fn append(len: usize, max: usize) -> Vec<usize> {
let mut v = vec![1; len];
v.append(&mut vec![0; max - v.len()]);
v
}
pub fn resize(len: usize, max: usize) -> Vec<usize> {
let mut v = Vec::with_capacity(max);
v.resize(len, 1);
v.resize(max, 0);
v
}
pub fn halfway(len: usize, max: usize) -> Vec<usize> {
let mut v = vec![1; len];
v.resize(max, 0);
v
}
pub fn overwrite(len: usize, max: usize) -> Vec<usize> {
let mut v = vec![1; max];
v[len..max].fill(0);
v
}
```
and the parameters were roughly:
```rust
for size in [10, 500, 1000, 5000] {
for max in [size, size + 1, size * 2, size * 10] {
```
and `resize` was consistently the fastest. `halfway` was similar most of
the time but consistently slightly slower. `overwrite` was slower than
those for reasons I don't understand and `append` was consistently the
slowest (though, of course, the difference was very small when we were
appending zero or one elements).
</details>
[^1]: I can't really read assembly but in [this small godbolt
example][0] I see `__rust_alloc`, `__rust_alloc_zeroed`, and
`do_reserve_and_handle` so I don't think the compiler is seeing the
upcoming allocation and handling it all on the initial allocation.
[0]: https://godbolt.org/z/eTsnjn9Tq
* Padding simplification for sequence generation pipelines
* Move call to `.get_pad_id` outside loop
**Why?**
Because it's the same for every iteration.
See [this comment][0] for more details.
[0]: https://github.com/guillaume-be/rust-bert/pull/254/files#r873138871
* Remove comments on `pad_features`
**Why?**
I tried to add some comments but didn't understand the problem space
well enough to correctly document what the returned masks do.
See [this comment][0] for more details.
[0]: https://github.com/guillaume-be/rust-bert/pull/254/files#r873138314
Co-authored-by: Guillaume Becquin <guillaume.becquin@gmail.com>
* Fixed Clippy warnings
* Revert "Shallow clone optimization (#243)"
This reverts commit ba584653bc.
* Made mode aggregation deterministic
* revert spurious change
* Moved BERT test to CPU allowing test suite to run with <8GB accelerator buffer
* Update src/pipelines/token_classification.rs
Co-authored-by: Mark Lodato <marklodato0@gmail.com>
* Update src/pipelines/token_classification.rs
Co-authored-by: Mark Lodato <marklodato0@gmail.com>
Co-authored-by: Mark Lodato <marklodato0@gmail.com>
**This Commit**
Attempts to simplify the `predict` function in the
`token_classification` pipeline by substituting a `HashMap` whose keys
are indices into a `Vec`.
**Why?**
Because the `HashMap` eagerly creates token buckets for all indices from
`0..input.len()` we can get the same behavior by using a `Vec`. This
cleans up some later code that was sorting on index because the `Vec`
maintains order by index naturally.
**Note**
I also switched from `get_mut().unwrap()` to `[]` notation because it
was the same but shorter. Happy to revert that if the
`get_mut().unwrap()` is specifically preferred for quickly finding panic
points by grepping for `unwrap` or something!
**Note**
I wrote a benchmark and it didn't seem to make it faster or slower but
hopefully that benchmark will be slightly helpful to those in the future
🤞.
* Fixed Clippy warnings
* Revert "Shallow clone optimization (#243)"
This reverts commit ba584653bc.
* Addition of defaults for Albert and BART configs
* Addition of BERT, DeBERTa, DeBERTaV2 default configs
* Addition of DistilBERT, Electra, FNet, GPT2, GPTNeo, Longformer configs
* Addition of default for all model configurations
* Cleaned-up config aliases and fixed tests
* Fixed Clippy warnings
Selects the correct Option<Tensor> for attention in AlbertTransformer.
Besides all_hidden_states might also be incorrect.
Co-authored-by: guillaume-be <guillaume.becquin@gmail.com>