diff --git a/CHANGELOG.md b/CHANGELOG.md index c9d57666..40fff22f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,427 +1,651 @@ # Changelog -All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). + +All notable changes to this project will be documented in this file. The format is based +on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] +## [0.23.0] - 2024-01-20 + ## Changed -- (BREAKING) Upgraded to `torch` 2.2 (via `tch` 0.15.0). + +- (BREAKING) Upgraded to `torch` 2.4 (via `tch` 0.17.0). ## [0.22.0] - 2024-01-20 + ## Added -- Addition of `new_with_tokenizer` constructor for `SentenceEmbeddingsModel` allowing passing custom tokenizers for sentence embeddings pipelines. -- Support for [Tokenizers](https://github.com/huggingface/tokenizers) in pipelines, allowing loading `tokenizer.json` and `special_token_map.json` tokenizer files. -- (BREAKING) Most model configuration can now take an optional `kind` parameter to specify the model weight precision. If not provided, will default to full precision on CPU, or the serialized weights precision otherwise. + +- Addition of `new_with_tokenizer` constructor for `SentenceEmbeddingsModel` allowing passing custom tokenizers for + sentence embeddings pipelines. +- Support for [Tokenizers](https://github.com/huggingface/tokenizers) in pipelines, allowing loading `tokenizer.json` + and `special_token_map.json` tokenizer files. +- (BREAKING) Most model configuration can now take an optional `kind` parameter to specify the model weight precision. + If not provided, will default to full precision on CPU, or the serialized weights precision otherwise. ## Fixed -- (BREAKING) Fixed the keyword extraction pipeline for n-gram sizes > 2. Add new configuration option `tokenizer_forbidden_ngram_chars` to specify characters that should be excluded from n-grams (allows filtering n-grams spanning multiple sentences). + +- (BREAKING) Fixed the keyword extraction pipeline for n-gram sizes > 2. Add new configuration + option `tokenizer_forbidden_ngram_chars` to specify characters that should be excluded from n-grams (allows filtering + n-grams spanning multiple sentences). - Improved MPS device compatibility setting the `sparse_grad` flag to false for `gather` operations - Updated ONNX runtime backend version to 1.15.x - Issue with incorrect results for QA models with a tokenizer not using segment ids - Issue with GPT-J that was incorrectly tracking the gradients for the attention bias ## Changed + - (BREAKING) Upgraded to `torch` 2.1 (via `tch` 0.14.0). -- (BREAKING) Text generation traits and pipelines (including conversation, summarization and translation) now return a `Result` for improved error handling +- (BREAKING) Text generation traits and pipelines (including conversation, summarization and translation) now return + a `Result` for improved error handling ## [0.21.0] - 2023-06-03 + ## Added + - Addition of the [LongT5](https://arxiv.org/abs/2112.07916) model architecture and pretrained weights. -- Addition of `add_tokens` and `add_extra_ids` interface methods to the `TokenizerOption`. Allow building most pipeline with custom tokenizer via `new_with_tokenizer`. -- Addition of `get_tokenizer` and `get_tokenizer_mut` methods to all pipelines allowing to get a (mutable) reference to the pipeline tokenizer. +- Addition of `add_tokens` and `add_extra_ids` interface methods to the `TokenizerOption`. Allow building most pipeline + with custom tokenizer via `new_with_tokenizer`. +- Addition of `get_tokenizer` and `get_tokenizer_mut` methods to all pipelines allowing to get a (mutable) reference to + the pipeline tokenizer. - Addition of a `get_embedding_dim` method to get the dimension of the embeddings for sentence embeddings pipelines -- `get_vocab_size`, `get_decoder_start_token_id` and `get_prefix_and_forced_bos_id` for the `TokenizerOption` in pipelines +- `get_vocab_size`, `get_decoder_start_token_id` and `get_prefix_and_forced_bos_id` for the `TokenizerOption` in + pipelines - Addition of the [GPT-J](https://www.eleuther.ai/artifacts/gpt-j) model architecture - Addition of the [NLLB](https://arxiv.org/abs/2207.04672) model architecture and pretrained weights -- Addition of support for ONNX models (encoder, decoders, encoder-decoders) via the [ort](https://github.com/pykeio/ort) onnxruntime bindings -- Integration of ONNX models to the sequence classification, token classification, question answering, zero-shot classification, text generation, summarization and translation pipelines +- Addition of support for ONNX models (encoder, decoders, encoder-decoders) via the [ort](https://github.com/pykeio/ort) + onnxruntime bindings +- Integration of ONNX models to the sequence classification, token classification, question answering, zero-shot + classification, text generation, summarization and translation pipelines ## Changed -- Bumped the tokenizers dependency from 7.x to 8.x, exposing additional options for special token mapping and adding the NLLBTokenizer -- (BREAKING) Simplified the generation traits (removal of LMHeadModel and elimination of unnecessary specification for LanguageGenerator) -- (BREAKING) Upgraded to `torch` 2.0 (via `tch` 0.13.0). The process to automatically download the dependencies have changed, it must now be enabled via the `download-libtorch` feature flag. + +- Bumped the tokenizers dependency from 7.x to 8.x, exposing additional options for special token mapping and adding the + NLLBTokenizer +- (BREAKING) Simplified the generation traits (removal of LMHeadModel and elimination of unnecessary specification for + LanguageGenerator) +- (BREAKING) Upgraded to `torch` 2.0 (via `tch` 0.13.0). The process to automatically download the dependencies have + changed, it must now be enabled via the `download-libtorch` feature flag. - Read the `decoder_start_token_id` from the provided configuration rather than using a hard-coded default value -- (BREAKING) Changed the return type of the `LanguageGenerator` and pipelines functions `float`, `half`, `set_device` to `Result<(), RustBertError>` as these become fallible for ONNX models -- (BREAKING) Wrapped the model resources specification for the pipeline `Config` objects into an `Enum` to allow handling both torch-based and ONNX models. - The `model_resources` field now needs to be wrapped in the corresponding enum variant, e.g. `model_resources: ModelResources::TORCH(model_resource)` for Torch-based models -- (BREAKING) Added the `forced_bos_token_id` and `forced_eos_token_id` fields to text generation models. - If these are not None, this will trigger a forced BOS/EOS token generation at the first of `max_length` positions (aligns with the Pytorch Transformers library) +- (BREAKING) Changed the return type of the `LanguageGenerator` and pipelines functions `float`, `half`, `set_device` + to `Result<(), RustBertError>` as these become fallible for ONNX models +- (BREAKING) Wrapped the model resources specification for the pipeline `Config` objects into an `Enum` to allow + handling both torch-based and ONNX models. + The `model_resources` field now needs to be wrapped in the corresponding enum variant, + e.g. `model_resources: ModelResources::TORCH(model_resource)` for Torch-based models +- (BREAKING) Added the `forced_bos_token_id` and `forced_eos_token_id` fields to text generation models. + If these are not None, this will trigger a forced BOS/EOS token generation at the first of `max_length` positions ( + aligns with the Pytorch Transformers library) - Project structure refactoring (torch-based models moved under common module). Non-breaking change via re-exports. ## Fixed + - MIN/MAX computation for float-like (was set to infinity instead of min/max) - Remove the (unused) pooler from the set of weights for BERT Masked LM architecture ## [0.20.0] - 2023-01-21 + ## Added + - Addition of All-MiniLM-L6-V2 model weights - Addition of Keyword/Keyphrases extraction pipeline based on KeyBERT (https://github.com/MaartenGr/KeyBERT) - Addition of Masked Language Model pipeline, allowing to predict masked words. - Support for the CodeBERT language model with pretrained models for language detection and masked token prediction ## Changed -- Addition of type aliases for the controlled generation (`PrefixAllowedFunction`) and zero-shot classification (`ZeroShotTemplate`). + +- Addition of type aliases for the controlled generation (`PrefixAllowedFunction`) and zero-shot + classification (`ZeroShotTemplate`). - (BREAKING) `merges_resource` now optional for all pipelines. - Allow mixing local and remote resources in pipelines. - Upgraded to `torch` 1.13 (via `tch` 0.9.0). - (BREAKING) Made the `max_length` argument for generation methods and pipelines optional. -- (BREAKING) Changed return type of `ModelForSequenceClassification` and `ModelForTokenClassification` to `Result` allowing error handling if no labels are provided in the configuration. +- (BREAKING) Changed return type of `ModelForSequenceClassification` and `ModelForTokenClassification` + to `Result` allowing error handling if no labels are provided in the configuration. ## Fixed + - Fixed configuration check for RoBERTa models for sentence classification. -- Fixed a bug causing the input prompt to be truncated for text generation if the prompt length was longer than `max_length` +- Fixed a bug causing the input prompt to be truncated for text generation if the prompt length was longer + than `max_length` ## [0.19.0] - 2022-07-24 + ## Added + - Support for sentence embeddings models and pipelines, based on [SentenceTransformers](https://www.sbert.net). ## Changed + - Upgraded to `torch` 1.12 (via `tch` 0.8.0) ## Fixed + - Allow empty slices or slices of empty prompts for text generation. ## [0.18.0] - 2022-05-29 + ## Added + - Addition of the DeBERTa language model and support for question answering, sequence and token classification - Addition of the DeBERTa v2/v3 language model and support for question answering, sequence and token classification -- Addition of a `new_with_tokenizer` method allowing building language model generator with a custom tokenizer (or pairing a tokenizer that was not originally designed with the model, e.g. T5 tokenizer with GPT2 model). +- Addition of a `new_with_tokenizer` method allowing building language model generator with a custom tokenizer (or + pairing a tokenizer that was not originally designed with the model, e.g. T5 tokenizer with GPT2 model). - (BREAKING) Addition of support for mT5 model, addition of new optional fields to T5Config -- Addition of `token_scores` field when `output_scores` is set to `true` for generation, returning the score for each token generated +- Addition of `token_scores` field when `output_scores` is set to `true` for generation, returning the score for each + token generated - Addition of `offsets` to entities generated in the `NER` pipeline ## Changed -- (BREAKING) Updated `Resources`, moving `RemoteResource` and associated download utilities/dependencies behind a feature gate (enabled by default). Reworked the API for building and using resources. + +- (BREAKING) Updated `Resources`, moving `RemoteResource` and associated download utilities/dependencies behind a + feature gate (enabled by default). Reworked the API for building and using resources. - Upgraded to `torch` 1.11 (via `tch` 0.7.2) -- Simplified token classification pipeline and mode aggregation now deterministic (fall back to the highest score for equally common labels) +- Simplified token classification pipeline and mode aggregation now deterministic (fall back to the highest score for + equally common labels) ## Fixed + - Fixed sinusoidal embeddings not being updated when loading a state dictionary (DistilBERT) ## [0.17.0] - 2021-12-19 + ## Changed + - Updated to `tch` 0.6.1 (libtorch 1.10) -- (BREAKING) Simplified the generics for multiple library traits taking as a rule `&[AsRef]` or `&str` as inputs (no longer accepts owned types `Vec` and `String`) +- (BREAKING) Simplified the generics for multiple library traits taking as a rule `&[AsRef]` or `&str` as inputs ( + no longer accepts owned types `Vec` and `String`) ## Added -- (BREAKING) Support for `bad_word_ids` generation, allowing to ban a set of word ids for all model supporting text generation -- Support for half-precision mode for all models (reducing memory footprint). A model can be converted to half-precision by calling the `half()` method on the `VarStore` is it currently stored in. Half-precision Torch kernels are not available for CPU (limited to CUDA devices) -- (BREAKING) Extension of the generation options that can be provided at runtime (after a model has been instantiated with a `GenerateConfig`), allowing to update the generation options from one text generation to another with the same model. This feature is implemented at the `LanguageGenerator` trait level, the high-level `TextGeneration` pipeline API remains unchanged. -- Addition of the FNet language model and support for sequence, token and multiple choice classification, question answering -- Addition of a full entities' prediction method supporting the IOBES scheme (merging entities token such as + -> ) + +- (BREAKING) Support for `bad_word_ids` generation, allowing to ban a set of word ids for all model supporting text + generation +- Support for half-precision mode for all models (reducing memory footprint). A model can be converted to half-precision + by calling the `half()` method on the `VarStore` is it currently stored in. Half-precision Torch kernels are not + available for CPU (limited to CUDA devices) +- (BREAKING) Extension of the generation options that can be provided at runtime (after a model has been instantiated + with a `GenerateConfig`), allowing to update the generation options from one text generation to another with the same + model. This feature is implemented at the `LanguageGenerator` trait level, the high-level `TextGeneration` pipeline + API remains unchanged. +- Addition of the FNet language model and support for sequence, token and multiple choice classification, question + answering +- Addition of a full entities' prediction method supporting the IOBES scheme (merging entities token such + as + -> ) ## [0.16.0] - 2021-08-24 + ## Added -- (BREAKING) Support for `prefix_allowed_tokens_fn` argument for generation, allowing users to control the generation via custom functions -- (BREAKING) Support for `forced_bos_token_id` argument for generation, allowing users to force a given BOS token for generation (useful for MBart/M2M-class models) -- (BREAKING) Support for `output_scores` boolean argument for generation, allowing users to output the log-probability scores of generated sequences. Updated the return type of low-level generate API to `GeneratedTextOutput` and `GeneratedIndicesOutput` containing optional scores along with the generated output. + +- (BREAKING) Support for `prefix_allowed_tokens_fn` argument for generation, allowing users to control the generation + via custom functions +- (BREAKING) Support for `forced_bos_token_id` argument for generation, allowing users to force a given BOS token for + generation (useful for MBart/M2M-class models) +- (BREAKING) Support for `output_scores` boolean argument for generation, allowing users to output the log-probability + scores of generated sequences. Updated the return type of low-level generate API to `GeneratedTextOutput` + and `GeneratedIndicesOutput` containing optional scores along with the generated output. - Addition of the MBart Language model and support for text generation / direct translation between 50 language - Addition of the M2M100 Language model and support for text generation / direct translation between 100 language ## Changed -- Updated GPT2 architecture to re-use embeddings for the output projection layer (resulting in smaller model weights files and memory footprint) + +- Updated GPT2 architecture to re-use embeddings for the output projection layer (resulting in smaller model weights + files and memory footprint) - Upgraded `tch` version to 0.5.0 (using `libtorch` 1.9.0) -- Changed default value of `no_repeat_ngram_size` for text generation from 3 to 0, aligning with [Python's Transformers](https://huggingface.co/transformers/main_classes/model.html?highlight=no_repeat_ngram_size#transformers.generation_utils.GenerationMixin.generate) -- Added the possibility to handle long inputs for token classification tasks (exceeding the model maximum length) using sliding windows over the input +- Changed default value of `no_repeat_ngram_size` for text generation from 3 to 0, aligning + with [Python's Transformers](https://huggingface.co/transformers/main_classes/model.html?highlight=no_repeat_ngram_size#transformers.generation_utils.GenerationMixin.generate) +- Added the possibility to handle long inputs for token classification tasks (exceeding the model maximum length) using + sliding windows over the input - (BREAKING) Generalized borrowing of Tensors as input for models - Aligned the optional `all_hidden_states` output for all models ## Fixed -- Updated T5 Decoder cross-attention to no longer use relative position bias (aligned with [Python reference update](https://github.com/huggingface/transformers/pull/8518)) -- Removed hardcoded maximum length for sequence and token classification tasks, now using the model maximum position embeddings instead + +- Updated T5 Decoder cross-attention to no longer use relative position bias (aligned + with [Python reference update](https://github.com/huggingface/transformers/pull/8518)) +- Removed hardcoded maximum length for sequence and token classification tasks, now using the model maximum position + embeddings instead ## [0.15.1] - 2021-06-01 + ### Fixed + - Fixed conversation model panic for user inputs exceeding the maximum model length (1000 tokens) - Fixed translation model panic for user inputs exceeding the maximum number of position embeddings ## [0.15.0] - 2021-05-16 + ### Added -- Addition of translation language pairs: - - English <-> Chinese (Simplified) - - English <-> Chinese (Traditional) - - English <-> Dutch - - English <-> Swedish - - English <-> Arabic - - English <-> Hebrew - - English <-> Hindi -- Addition of a Part of Speech pipeline. This pipeline allows predicting the POS tag (e.g. Noun, Adjective, Verb) of words in input sentences. + +- Addition of translation language pairs: + - English <-> Chinese (Simplified) + - English <-> Chinese (Traditional) + - English <-> Dutch + - English <-> Swedish + - English <-> Arabic + - English <-> Hebrew + - English <-> Hindi +- Addition of a Part of Speech pipeline. This pipeline allows predicting the POS tag (e.g. Noun, Adjective, Verb) of + words in input sentences. - Addition of a lightweight English Part of Speech tagging pretrained MobileBERT model - Addition of the Pegasus language model and support for conditional generation - Addition of a model for Pegasus summarization pretrained on the CNN-DM dataset -- Addition of the GPT-Neo language model and pretrained snapshots (125M, 1.3B and 2.7B parameters). Registration of GPT-Neo as an option for `TextGenerationPipeline`. +- Addition of the GPT-Neo language model and pretrained snapshots (125M, 1.3B and 2.7B parameters). Registration of + GPT-Neo as an option for `TextGenerationPipeline`. ### Changed -- (BREAKING) Changed `classif_dropout` in `BartConfig` to be an optional field. This affects dependencies instantiating `BartConfig` from scratch, or using `classif_config` for custom model heads. -- (BREAKING) Changed token classification pipelines to return a Vec> instead of a Vec. The token-level predictions are now returned in separate vectors for each input sequence provided as an input (they were previously returned in a flattened vector) + +- (BREAKING) Changed `classif_dropout` in `BartConfig` to be an optional field. This affects dependencies + instantiating `BartConfig` from scratch, or using `classif_config` for custom model heads. +- (BREAKING) Changed token classification pipelines to return a Vec> instead of a Vec. The token-level + predictions are now returned in separate vectors for each input sequence provided as an input (they were previously + returned in a flattened vector) - Simplification of the BART language model code base (also used for Marian and Pegasus language models) - (BREAKING) Updated to `tch 0.4.1` (based on `libtorch 1.8.1`) ### Fixed + - Fixed character indexing error for Question Answering pipeline answers ### Removed + - Dependency to `itertools` crate ## [0.14.0] - 2021-02-22 + ### Added + - Addition of the Longformer language model, task-specific heads and registration in relevant pipelines ### Changed -- (BREAKING) Exposed additional settings for the Question Answering pipeline related to the maximum question, context and answer length. This is not backward compatible if the question answering configuration was created without using the `new` creator. -- Simplified the Question answering pipeline to rely on the offsets calculated by the tokenizers instead of a manual alignment. This results in moderate execution speed improvements for this pipeline. -- Updated the padding strategy for the Question answering pipeline. While before all sequences were padded to a fixed `max_length` (defaulting to 384), the padding is now done dynamically based on the length of the inputs. This results in a significant speed improvement for this pipeline. + +- (BREAKING) Exposed additional settings for the Question Answering pipeline related to the maximum question, context + and answer length. This is not backward compatible if the question answering configuration was created without using + the `new` creator. +- Simplified the Question answering pipeline to rely on the offsets calculated by the tokenizers instead of a manual + alignment. This results in moderate execution speed improvements for this pipeline. +- Updated the padding strategy for the Question answering pipeline. While before all sequences were padded to a + fixed `max_length` (defaulting to 384), the padding is now done dynamically based on the length of the inputs. This + results in a significant speed improvement for this pipeline. ### Fixed -- Fixed a bug for Question Answering for models that were not based on Wordpiece tokenization (including BPE and unigram based tokenizers). The issue was caused by the pre-tokenization step that was stripping the leading whitespace for all tokens. The performance of these models for QA should improve significantly. + +- Fixed a bug for Question Answering for models that were not based on Wordpiece tokenization (including BPE and unigram + based tokenizers). The issue was caused by the pre-tokenization step that was stripping the leading whitespace for all + tokens. The performance of these models for QA should improve significantly. ## [0.13.0] - 2021-02-03 + ### Added + - Addition of the ProphetNet language model, task-specific heads and registration in relevant pipelines -- (BREAKING) Implementation of [Diverse Beam Search](https://arxiv.org/abs/1610.02424). This allows the generation of more diverse sequences within the number of beams. Addition of 2 new fields to the `GenerateConfig` that are propagated through all text generation configs (e.g. `TranslationConfig`): - - `num_beam_groups` (`Option`), indicating the number of sub-beam groups. This must be a divisor of the number of beams. - - `diversity_penalty` (`Option`), indicating by which amount to penalize common words between beam groups. This will default to 5.5 if not provided. The impact of this diverse beam search is illustrated in the GPT2 integration tests. +- (BREAKING) Implementation of [Diverse Beam Search](https://arxiv.org/abs/1610.02424). This allows the generation of + more diverse sequences within the number of beams. Addition of 2 new fields to the `GenerateConfig` that are + propagated through all text generation configs (e.g. `TranslationConfig`): + - `num_beam_groups` (`Option`), indicating the number of sub-beam groups. This must be a divisor of the number + of beams. + - `diversity_penalty` (`Option`), indicating by which amount to penalize common words between beam groups. This + will default to 5.5 if not provided. The impact of this diverse beam search is illustrated in the GPT2 integration + tests. ### Changed -- (BREAKING) Simplified the input and output of encoder/decoder models to avoid needing to take ownership of the possibly cached encoder hidden state, offering a minor performance improvement for text generation tasks. The model output field for encoder hidden states are now optional, and only returned if the encoder hidden states were not provided for the given forward path. This may be a breaking change for low-level dependencies that manipulate directly the encoder/decoder model outputs. -- (BREAKING) Moved the language models implementation of the `PrivateLanguageGenerator` and `LanguageGenerator` traits (needed to generate text) to the model modules, cleaning up the generation_utils module. + +- (BREAKING) Simplified the input and output of encoder/decoder models to avoid needing to take ownership of the + possibly cached encoder hidden state, offering a minor performance improvement for text generation tasks. The model + output field for encoder hidden states are now optional, and only returned if the encoder hidden states were not + provided for the given forward path. This may be a breaking change for low-level dependencies that manipulate directly + the encoder/decoder model outputs. +- (BREAKING) Moved the language models implementation of the `PrivateLanguageGenerator` and `LanguageGenerator` traits ( + needed to generate text) to the model modules, cleaning up the generation_utils module. - Updated download utilities crate, now leveraging Tokio 1.0 runtimes. ### Fixed -- Updated padding information and addition of position ids for batched GPT2 generation. Prior to this change, inputs that required padding had a lower quality for the text generated. + +- Updated padding information and addition of position ids for batched GPT2 generation. Prior to this change, inputs + that required padding had a lower quality for the text generated. ## [0.12.1] - 2021-01-04 + ### Added + - Addition of the MobileBERT language model, task-specific heads and registration in relevant pipelines ### Changed + - Made all model configurations `Clone` -- Made several base modules of the BERT language model public, and added model output `Struct` for the new publicly exposed, complex types +- Made several base modules of the BERT language model public, and added model output `Struct` for the new publicly + exposed, complex types ## [0.12.0] - 2020-11-29 + ### Added + - Addition of the Reformer language model, task-specific heads and registration in relevant pipelines - Pre-trained models for DistilRoBERTa, used as a default for integration tests ### Changed + - Updated endpoint of the model resources reflecting changes to the Hugging Face's model hub - Early stopping turned by default on for translation and summarization ## [0.11.0] - 2020-11-02 + ### Added + - Support for additional models for the conversational pipeline ### Changed + - Updated the version of Tokenizer crate with consistent visibility -- (BREAKING) move of teh text generation pipeline to its owned pipeline. Shared generation utilities are moved to `generation_utils` +- (BREAKING) move of teh text generation pipeline to its owned pipeline. Shared generation utilities are moved + to `generation_utils` - All models, tokenizers and pipelines are now `Send` ## [0.10.0] - 2020-10-04 + ### Added + - Benchmark scripts for all pipelines - Addition of the XLNet model and task-specific heads ### Changed -- (BREAKING) Changed the download method for resources now a method of the resource itself, and leveraging the cached-path crate. + +- (BREAKING) Changed the download method for resources now a method of the resource itself, and leveraging the + cached-path crate. - (BREAKING) Changed the return type of models to be output `Struct` instead of long tuples. -- (BREAKING) Changed the naming of the model main modules from `modelname` to `model_modelname` to avoid confusion with the top level module name -- Extended the range of allowed types for pipelines input, allowing both owned `Vec` and slices, and both `String` and sting slice. +- (BREAKING) Changed the naming of the model main modules from `modelname` to `model_modelname` to avoid confusion with + the top level module name +- Extended the range of allowed types for pipelines input, allowing both owned `Vec` and slices, and both `String` and + sting slice. - Handling of all activations functions is mow made from a common module and `Struct` ## [0.9.0] - 2020-09-06 + ### Added + - Zero-shot classification pipeline using a natural language inference model ### Changed -- (BREAKING) Updated version of tokenizers crate with added options for lower casing, accent stripping and prefix addition + +- (BREAKING) Updated version of tokenizers crate with added options for lower casing, accent stripping and prefix + addition - Updated BART classification model to allow running their `forward` method without being mutable. ## [0.8.0] - 2020-08-25 + ### Added + - (BREAKING) Improved error handling via the addition of `RustBertError` and error propagation throughout the crate. ### Changed + - Updated version of tokenizers crate with improved error handling ## [0.7.12] - 2020-08-12 + ### Added + - Addition of the reformer language model and its integration for language generation ### Changed + - Changed model resources endpoints to leverage updated Hugging Face's model hub - Updated the beam search processing to use vectorized operations ## [0.7.11] - 2020-07-26 + ### Changed -- Generalization of the accepted input for several pipelines to accept both `Vec` and slices, and to accept both `String` and `&str` + +- Generalization of the accepted input for several pipelines to accept both `Vec` and slices, and to accept + both `String` and `&str` ## [0.7.10] - 2020-07-08 + ### Added + - Addition of the ALBERT language model and task-specific heads - Addition of German - English translation models - Addition of the T5 language model and integration in supported pipelines (translation and summarization) ### Changed + - Updated the modules throughout the crate to accept both owned and references to varstore paths. ## [0.7.9] - 2020-06-28 + ### Added + - Addition of a multi-turn conversational pipeline based on DialoGPT. ## [0.7.8] - 2020-06-23 + ### Fixed + - Code formatting using `rustfmt` ## [0.7.7] - 2020-06-06 + ### Changed -- Removed the requirement for generation models to be mutable. Models are now all stateless, and no longer store an internal cache (now provided as an input). + +- Removed the requirement for generation models to be mutable. Models are now all stateless, and no longer store an + internal cache (now provided as an input). - Updated BART model to take past layer states as an input instead of storing in internally. ### Fixed + - Fixed sequence classification model logits squeeze causing it to crash for batched inputs. ## [0.7.6] - 2020-05-27 + ### Added + - Addition of translation between Russian and English ### Fixed -- Fixed a bug causing downloads to be incomplete, and removes the creation of a tokio runtime for the download of resources. + +- Fixed a bug causing downloads to be incomplete, and removes the creation of a tokio runtime for the download of + resources. ## [0.7.5] - 2020-05-25 + ### Added + - Addition of the Marian model, leveraging a shared language model implementation with the BART model. -- Addition of translation capabilities. Supports translation between English and French, Spanish, Portuguese, Italian, Catalan and German, and between German and French. +- Addition of translation capabilities. Supports translation between English and French, Spanish, Portuguese, Italian, + Catalan and German, and between German and French. ## [0.7.4] - 2020-05-25 + ### Added + - Addition of multi-label classification capabilities for sequence classification via the `predict_mutilabel` function. ## [0.7.3] - 2020-05-19 + ### Added -- Generalization of pipelines to allow leveraging multiple model architectures. Leveraging `Enum` unpacking, introduces `ConfigOption`, `TokenizerOption` and pipeline-specific Options. -- Addition of generic `SentenceClassificationModel` pipeline. The `SentimentModel` now leverages shared implementation for sentence classification. -- Addition of `TokenClassificationModel` pipeline. The `NERModel`now leverages shared implementation for token classification. + +- Generalization of pipelines to allow leveraging multiple model architectures. Leveraging `Enum` unpacking, + introduces `ConfigOption`, `TokenizerOption` and pipeline-specific Options. +- Addition of generic `SentenceClassificationModel` pipeline. The `SentimentModel` now leverages shared implementation + for sentence classification. +- Addition of `TokenClassificationModel` pipeline. The `NERModel`now leverages shared implementation for token + classification. ### Changed + - Major rework of tokenization crate, alignment with updated API ## [0.7.2] - 2020-05-03 + ### Fixed + - Minor bug fixes for tokenization ## [0.7.1] - 2020-05-03 + ### Added + - Implementation of the Electra model (generator, discriminator, task-specific heads) - GPT2-medium and GPT2-large models ## [0.7.0] - 2020-04-26 + ### Added -- Addition of Resources for handling file dependencies (e.g. vocabularies, model weights, configurations). Resources may be `LocalResources` (pointing to a filesystem location) or `RemoteResources` (pointing to a remote endpoint). These resources can be passed to a `download_resource` method that returns the location in the local filesystem for both types of resources, downloading them if necessary. + +- Addition of Resources for handling file dependencies (e.g. vocabularies, model weights, configurations). Resources may + be `LocalResources` (pointing to a filesystem location) or `RemoteResources` (pointing to a remote endpoint). These + resources can be passed to a `download_resource` method that returns the location in the local filesystem for both + types of resources, downloading them if necessary. - Resources specifications for all existing architectures, pointing to model files hosted on Hugging Face's model hub. ### Changed + - (BREAKING) moved the resources' specification to the `GenerateConfig` for `GPT2Generator`. -- (BREAKING) creation of pipeline configurations to contain the resources required to build the pipeline, used as an input rather than paths to local files. -- Updated the configuration for the number of target labels to use the `id2label` field instead of `num_labels` (aligning with changes in standard configuration in the Transformers library). Removed `num_labels` from configurations. +- (BREAKING) creation of pipeline configurations to contain the resources required to build the pipeline, used as an + input rather than paths to local files. +- Updated the configuration for the number of target labels to use the `id2label` field instead of `num_labels` ( + aligning with changes in standard configuration in the Transformers library). Removed `num_labels` from + configurations. - Made the `output_attentions`, `output_hidden_states` and `torchscript` fields for DistilBERT configuration optional - Fixed the device placement for sinusoidal embeddings for DistilBERT model. ## [0.6.2] - 2020-04-07 + ### Changed + - Optimization of the BART model avoiding unnecessary tensor copies for cache manipulation and residual connections. - Optimization of DistilBERT model when embeddings are provided as an input ## [0.6.1] - 2020-04-06 + ### Changed + - Minor optimizations to question answering and sentiment analysis pipelines - Addition of a cache reset for text generation routines - Implementation of cache reset for BART language model ## [0.6.0] - 2020-04-05 + ### Added + - BART language model -- Implementation of `LanguageModel` and `PrivateLanguageModel` for BART +- Implementation of `LanguageModel` and `PrivateLanguageModel` for BART - Summarization capabilities - Tanh activation ### Changed + - (BREAKING) Moved the `LMHeadModel` Trait from GPT2 module to the pipelines module -- Updated the `LMHeadModel` inputs to include `encoder_outputs` and `decoder_input_ids` to support causal language model (e.g. BART) +- Updated the `LMHeadModel` inputs to include `encoder_outputs` and `decoder_input_ids` to support causal language + model (e.g. BART) - (BREAKING) Added methods to the `PrivateLanguageGenerator` to support encoder-decoder models -- (BREAKING) changed the type of `Generator` language model to require mutability (BART caching mechanism stores the cache in the model requiring the entire model mutability - changed at a later point) +- (BREAKING) changed the type of `Generator` language model to require mutability (BART caching mechanism stores the + cache in the model requiring the entire model mutability - changed at a later point) - Optimization of the `get_banned_token` method ### Fixed -- Updated the device location of the token update when EOS is not allowed because the minimum sequence length was not reached + +- Updated the device location of the token update when EOS is not allowed because the minimum sequence length was not + reached - No longer process a given beam hypothesis if it is marked as done - No longer add beams to a hypothesis if the rank is lower than the number of beams - Updated final beam update to skip completed hypotheses ## [0.5.3] - 2020-03-27 + ### Added + - Documentation throughout the crate - Creation of a `GenerateConfig` configuration structure to hold generation options ### Changed + - Visibility of low-level utilities in the crate -- Updated the generation options to be passed at the text generation model instantiation, rather than at every call to the `generate` method +- Updated the generation options to be passed at the text generation model instantiation, rather than at every call to + the `generate` method - Updated visibility of generation routines into a public API and private lower level methods ## [0.5.2] - 2020-03-17 + ### Changed -- Text generation now takes a `Option>` instead of a `Option<&str>`. Shorter sequences are left-padded with `pad` if available, otherwise with `eos`. + +- Text generation now takes a `Option>` instead of a `Option<&str>`. Shorter sequences are left-padded + with `pad` if available, otherwise with `eos`. - Turned-off gradient calculations for generation process ## [0.5.1] - 2020-03-16 + ### Fixed + - Beam search completion validation - Padding sequence for sentences shorter than the maximum length moved to correct device ## [0.5.0] - 2020-03-16 + ### Added + - DistilGPT2 pretrained weights for GPT2 -- `LMHeadModel` trait for model supporting text generation, offering an interface between the model specific input/output, and the generic set of inputs/outputs expected for model supporting text generation +- `LMHeadModel` trait for model supporting text generation, offering an interface between the model specific + input/output, and the generic set of inputs/outputs expected for model supporting text generation - Implementation of `LMHeadModel` for GPT2 and GPT -- Text generation pipeline, supporting beam search, top-k/top-p decoding, repeated tokens banning, repetition and length penalties as `LanguageGenerator` Trait +- Text generation pipeline, supporting beam search, top-k/top-p decoding, repeated tokens banning, repetition and length + penalties as `LanguageGenerator` Trait - Implementation of `LanguageGenerator` for GPT and GPT2 - Examples and tests for language generation ### Fixed + - Fixed concatenation dimension for GPT2 past ## [0.4.5] - 2020-03-07 + ### Changed -- Updated input type for `QuestionAnsweringModel`'s `predict` to be `&[QaInput]` instead of a pair of question and context strings. QuestionAnsweringModel now works with a list of inputs and returns a list of predictions, processing inputs as batches. + +- Updated input type for `QuestionAnsweringModel`'s `predict` to be `&[QaInput]` instead of a pair of question and + context strings. QuestionAnsweringModel now works with a list of inputs and returns a list of predictions, processing + inputs as batches. ## [0.4.4] - 2020-03-01 + ### Added + - Swish and gelu_new activation functions - GPT2 language model - GPT language model ## [0.4.3] - 2020-02-25 + ### Added + - Addition of a NER pipeline - Addition of a QuestionAnswering pipeline ### Changed + - Moved `SentimentClassifier` from DistilBERT module to the newly created pipelines - Changed precision of id to label mapping of BERT config from `i32` to `i64` - Simplified calculation of sinusoidal embeddings for DistilBERT ## [0.4.1] - 2020-02-21 + ### Added + - Addition of RoBERTa language model - Addition of `BertEmbedding` trait for BERT-like models ### Changed + - Updated `BertEmbeddings` to implement the newly created `BertEmbedding` Trait -- Updated `BertModel`'s embeddings to be of type `impl BertEmbedding` rather than specific embeddings, allowing to re-use the BERT structure for other models, only replacing the embeddings layer. +- Updated `BertModel`'s embeddings to be of type `impl BertEmbedding` rather than specific embeddings, allowing to + re-use the BERT structure for other models, only replacing the embeddings layer. ### Fixed -- Fixed the variable path for BERT models with task-specific heads to allow loading a snapshot from models trained on Transformers. + +- Fixed the variable path for BERT models with task-specific heads to allow loading a snapshot from models trained on + Transformers. ## [0.4.0] - 2020-02-18 + ### Added + - BERT Model and examples - Addition of `DistilBertForTokenClassification` and `DistilBertForQuestionAnswering` model heads - Collection of activation functions (gelu, relu, mish) @@ -430,24 +654,33 @@ All notable changes to this project will be documented in this file. The format - Config trait allowing to deserialize from `json` files ### Changed + - (BREAKING) Updated `DistilBertConfig` to use the newly created `Config` Trait ## [0.3.1] - 2020-02-16 + ### Added + - Integration tests ### Changed + - Migrated from `rust_transformers` v0.2.0 (deprecated) to `rust_tokenizers v1.0.0 ## [0.3.0] - 2020-02-13 + ### Added + - Example for DistilBERT masked language modeling - Download utilities script for DistilBERT (base and SST2) ### Changed -- made `label2id`, `id2label`, `is_decoder`, `output_past` and `use_bfloat` configuration fields optional for DistilBertConfig + +- made `label2id`, `id2label`, `is_decoder`, `output_past` and `use_bfloat` configuration fields optional for + DistilBertConfig ## [0.2.0] - 2020-02-11 + ### Initial release - Tensor conversion tools from Pytorch to Libtorch format diff --git a/Cargo.toml b/Cargo.toml index 200e5d7a..d0f0b807 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rust-bert" -version = "0.22.0" +version = "0.23.0" authors = ["Guillaume Becquin "] edition = "2018" description = "Ready-to-use NLP pipelines and language models" diff --git a/README.md b/README.md index e3f380f7..c2112a4f 100644 --- a/README.md +++ b/README.md @@ -21,12 +21,12 @@ translation, summarization, text generation, conversational agents and more in just a few lines of code: ```rust - let qa_model = QuestionAnsweringModel::new(Default::default())?; - - let question = String::from("Where does Amy live ?"); - let context = String::from("Amy lives in Amsterdam"); + let qa_model = QuestionAnsweringModel::new(Default::default ()) ?; - let answers = qa_model.predict(&[QaInput { question, context }], 1, 32); +let question = String::from("Where does Amy live ?"); +let context = String::from("Amy lives in Amsterdam"); + +let answers = qa_model.predict( & [QaInput { question, context }], 1, 32); ``` Output: @@ -54,32 +54,32 @@ The tasks currently supported include: Expand to display the supported models/tasks matrix | | **Sequence classification** | **Token classification** | **Question answering** | **Text Generation** | **Summarization** | **Translation** | **Masked LM** | **Sentence Embeddings** | -| :----------: | :-------------------------: | :----------------------: | :--------------------: | :-----------------: | :---------------: | :-------------: | :-----------: | :---------------------: | -| DistilBERT | ✅ | ✅ | ✅ | | | | ✅ | ✅ | -| MobileBERT | ✅ | ✅ | ✅ | | | | ✅ | | -| DeBERTa | ✅ | ✅ | ✅ | | | | ✅ | | -| DeBERTa (v2) | ✅ | ✅ | ✅ | | | | ✅ | | -| FNet | ✅ | ✅ | ✅ | | | | ✅ | | -| BERT | ✅ | ✅ | ✅ | | | | ✅ | ✅ | -| RoBERTa | ✅ | ✅ | ✅ | | | | ✅ | ✅ | -| GPT | | | | ✅ | | | | | -| GPT2 | | | | ✅ | | | | | -| GPT-Neo | | | | ✅ | | | | | -| GPT-J | | | | ✅ | | | | | -| BART | ✅ | | | ✅ | ✅ | | | | -| Marian | | | | | | ✅ | | | -| MBart | ✅ | | | ✅ | | | | | -| M2M100 | | | | ✅ | | | | | -| NLLB | | | | ✅ | | | | | -| Electra | | ✅ | | | | | ✅ | | -| ALBERT | ✅ | ✅ | ✅ | | | | ✅ | ✅ | -| T5 | | | | ✅ | ✅ | ✅ | | ✅ | -| LongT5 | | | | ✅ | ✅ | | | | -| XLNet | ✅ | ✅ | ✅ | ✅ | | | ✅ | | -| Reformer | ✅ | | ✅ | ✅ | | | ✅ | | -| ProphetNet | | | | ✅ | ✅ | | | | -| Longformer | ✅ | ✅ | ✅ | | | | ✅ | | -| Pegasus | | | | | ✅ | | | | +|:------------:|:---------------------------:|:------------------------:|:----------------------:|:-------------------:|:-----------------:|:---------------:|:-------------:|:-----------------------:| +| DistilBERT | ✅ | ✅ | ✅ | | | | ✅ | ✅ | +| MobileBERT | ✅ | ✅ | ✅ | | | | ✅ | | +| DeBERTa | ✅ | ✅ | ✅ | | | | ✅ | | +| DeBERTa (v2) | ✅ | ✅ | ✅ | | | | ✅ | | +| FNet | ✅ | ✅ | ✅ | | | | ✅ | | +| BERT | ✅ | ✅ | ✅ | | | | ✅ | ✅ | +| RoBERTa | ✅ | ✅ | ✅ | | | | ✅ | ✅ | +| GPT | | | | ✅ | | | | | +| GPT2 | | | | ✅ | | | | | +| GPT-Neo | | | | ✅ | | | | | +| GPT-J | | | | ✅ | | | | | +| BART | ✅ | | | ✅ | ✅ | | | | +| Marian | | | | | | ✅ | | | +| MBart | ✅ | | | ✅ | | | | | +| M2M100 | | | | ✅ | | | | | +| NLLB | | | | ✅ | | | | | +| Electra | | ✅ | | | | | ✅ | | +| ALBERT | ✅ | ✅ | ✅ | | | | ✅ | ✅ | +| T5 | | | | ✅ | ✅ | ✅ | | ✅ | +| LongT5 | | | | ✅ | ✅ | | | | +| XLNet | ✅ | ✅ | ✅ | ✅ | | | ✅ | | +| Reformer | ✅ | | ✅ | ✅ | | | ✅ | | +| ProphetNet | | | | ✅ | ✅ | | | | +| Longformer | ✅ | ✅ | ✅ | | | | ✅ | | +| Pegasus | | | | | ✅ | | | | @@ -100,7 +100,7 @@ models used by this library are in the order of the 100s of MBs to GBs. ### Manual installation (recommended) 1. Download `libtorch` from https://pytorch.org/get-started/locally/. This - package requires `v2.2`: if this version is no longer available on the "get + package requires `v2.4`: if this version is no longer available on the "get started" page, the file should be accessible by modifying the target link, for example `https://download.pytorch.org/libtorch/cu124/libtorch-cxx11-abi-shared-with-deps-2.4.0%2Bcu124.zip` @@ -188,7 +188,7 @@ files. These files are expected (but not all are necessary) for use in this library as per the table below: | Architecture | Encoder file | Decoder without past file | Decoder with past file | -| --------------------------- | ------------ | ------------------------- | ---------------------- | +|-----------------------------|--------------|---------------------------|------------------------| | Encoder (e.g. BERT) | required | not used | not used | | Decoder (e.g. GPT2) | not used | required | optional | | Encoder-decoder (e.g. BART) | required | required | optional | @@ -227,12 +227,12 @@ Extractive question answering from a given question and context. DistilBERT model fine-tuned on SQuAD (Stanford Question Answering Dataset) ```rust - let qa_model = QuestionAnsweringModel::new(Default::default())?; - - let question = String::from("Where does Amy live ?"); - let context = String::from("Amy lives in Amsterdam"); + let qa_model = QuestionAnsweringModel::new(Default::default ()) ?; + +let question = String::from("Where does Amy live ?"); +let context = String::from("Amy lives in Amsterdam"); - let answers = qa_model.predict(&[QaInput { question, context }], 1, 32); +let answers = qa_model.predict( & [QaInput { question, context }], 1, 32); ``` Output: @@ -281,7 +281,7 @@ is available in the ```rust use rust_bert::pipelines::translation::{Language, TranslationModelBuilder}; fn main() -> anyhow::Result<()> { -let model = TranslationModelBuilder::new() + let model = TranslationModelBuilder::new() .with_source_languages(vec![Language::English]) .with_target_languages(vec![Language::Spanish, Language::French, Language::Italian]) .create_model()?; @@ -308,9 +308,9 @@ Il s'agit d'une phrase à traduire Abstractive summarization using a pretrained BART model. ```rust - let summarization_model = SummarizationModel::new(Default::default())?; - - let input = ["In findings published Tuesday in Cornell University's arXiv by a team of scientists \ + let summarization_model = SummarizationModel::new(Default::default ()) ?; + +let input = ["In findings published Tuesday in Cornell University's arXiv by a team of scientists \ from the University of Montreal and a separate report published Wednesday in Nature Astronomy by a team \ from University College London (UCL), the presence of water vapour was confirmed in the atmosphere of K2-18b, \ a planet circling a star in the constellation Leo. This is the first such discovery in a planet in its star's \ @@ -332,7 +332,7 @@ on K2-18b lasts 33 Earth days. According to The Guardian, astronomers were optim telescope — scheduled for launch in 2021 — and the European Space Agency's 2028 ARIEL program, could reveal more \ about exoplanets like K2-18b."]; - let output = summarization_model.summarize(&input); +let output = summarization_model.summarize( & input); ``` (example from: @@ -367,11 +367,11 @@ generate responses to them. ```rust use rust_bert::pipelines::conversation::{ConversationModel, ConversationManager}; -let conversation_model = ConversationModel::new(Default::default()); +let conversation_model = ConversationModel::new(Default::default ()); let mut conversation_manager = ConversationManager::new(); let conversation_id = conversation_manager.create("Going to the movies tonight - any suggestions?"); -let output = conversation_model.generate_responses(&mut conversation_manager); +let output = conversation_model.generate_responses( & mut conversation_manager); ``` Example output: @@ -393,17 +393,17 @@ present, the unknown token otherwise. This may impact the results, it is recommended to submit prompts of similar length for best results ```rust - let model = GPT2Generator::new(Default::default())?; - - let input_context_1 = "The dog"; - let input_context_2 = "The cat was"; + let model = GPT2Generator::new(Default::default ()) ?; - let generate_options = GenerateOptions { - max_length: 30, - ..Default::default() - }; +let input_context_1 = "The dog"; +let input_context_2 = "The cat was"; - let output = model.generate(Some(&[input_context_1, input_context_2]), generate_options); +let generate_options = GenerateOptions { +max_length: 30, +..Default::default () +}; + +let output = model.generate(Some( & [input_context_1, input_context_2]), generate_options); ``` Example output: @@ -428,18 +428,18 @@ Performs zero-shot classification on input sentences with provided labels using a model fine-tuned for Natural Language Inference. ```rust - let sequence_classification_model = ZeroShotClassificationModel::new(Default::default())?; + let sequence_classification_model = ZeroShotClassificationModel::new(Default::default ()) ?; - let input_sentence = "Who are you voting for in 2020?"; - let input_sequence_2 = "The prime minister has announced a stimulus package which was widely criticized by the opposition."; - let candidate_labels = &["politics", "public health", "economics", "sports"]; +let input_sentence = "Who are you voting for in 2020?"; +let input_sequence_2 = "The prime minister has announced a stimulus package which was widely criticized by the opposition."; +let candidate_labels = & ["politics", "public health", "economics", "sports"]; - let output = sequence_classification_model.predict_multilabel( - &[input_sentence, input_sequence_2], - candidate_labels, - None, - 128, - ); +let output = sequence_classification_model.predict_multilabel( +& [input_sentence, input_sequence_2], +candidate_labels, +None, +128, +); ``` Output: @@ -460,15 +460,15 @@ Predicts the binary sentiment for a sentence. DistilBERT model fine-tuned on SST-2. ```rust - let sentiment_classifier = SentimentModel::new(Default::default())?; - - let input = [ - "Probably my all-time favorite movie, a story of selflessness, sacrifice and dedication to a noble cause, but it's not preachy or boring.", - "This film tried to be too many things all at once: stinging political satire, Hollywood blockbuster, sappy romantic comedy, family values promo...", - "If you like original gut wrenching laughter you will like this movie. If you are young or old then you will love this movie, hell even my mom liked it.", - ]; + let sentiment_classifier = SentimentModel::new(Default::default ()) ?; + +let input = [ +"Probably my all-time favorite movie, a story of selflessness, sacrifice and dedication to a noble cause, but it's not preachy or boring.", +"This film tried to be too many things all at once: stinging political satire, Hollywood blockbuster, sappy romantic comedy, family values promo...", +"If you like original gut wrenching laughter you will like this movie. If you are young or old then you will love this movie, hell even my mom liked it.", +]; - let output = sentiment_classifier.predict(&input); +let output = sentiment_classifier.predict( & input); ``` (Example courtesy of [IMDb](http://www.imdb.com)) @@ -494,14 +494,14 @@ BERT cased large model fine-tuned on CoNNL03, contributed by the Models are currently available for English, German, Spanish and Dutch. ```rust - let ner_model = NERModel::new(default::default())?; + let ner_model = NERModel::new( default::default ()) ?; + +let input = [ +"My name is Amy. I live in Paris.", +"Paris is a city in France." +]; - let input = [ - "My name is Amy. I live in Paris.", - "Paris is a city in France." - ]; - - let output = ner_model.predict(&input); +let output = ner_model.predict( & input); ``` Output: @@ -529,7 +529,7 @@ Extract keywords and keyphrases extractions from input documents ```rust fn main() -> anyhow::Result<()> { let keyword_extraction_model = KeywordExtractionModel::new(Default::default())?; - + let input = "Rust is a multi-paradigm, general-purpose programming language. \ Rust emphasizes performance, type safety, and concurrency. Rust enforces memory safety—that is, \ that all references point to valid memory—without requiring the use of a garbage collector or \ @@ -560,11 +560,11 @@ Output: Extracts Part of Speech tags (Noun, Verb, Adjective...) from text. ```rust - let pos_model = POSModel::new(default::default())?; + let pos_model = POSModel::new( default::default ()) ?; + +let input = ["My name is Bob"]; - let input = ["My name is Bob"]; - - let output = pos_model.predict(&input); +let output = pos_model.predict( & input); ``` Output: @@ -588,15 +588,15 @@ applications including dense information retrieval. ```rust let model = SentenceEmbeddingsBuilder::remote( - SentenceEmbeddingsModelType::AllMiniLmL12V2 - ).create_model()?; +SentenceEmbeddingsModelType::AllMiniLmL12V2 +).create_model() ?; + +let sentences = [ +"this is an example sentence", +"each sentence is converted" +]; - let sentences = [ - "this is an example sentence", - "each sentence is converted" - ]; - - let output = model.encode(&sentences)?; +let output = model.encode( & sentences) ?; ``` Output: @@ -616,14 +616,14 @@ Output: Predict masked words in input sentences. ```rust - let model = MaskedLanguageModel::new(Default::default())?; - - let sentences = [ - "Hello I am a student", - "Paris is the of France. It is in Europe.", - ]; - - let output = model.predict(&sentences); + let model = MaskedLanguageModel::new(Default::default ()) ?; + +let sentences = [ +"Hello I am a student", +"Paris is the of France. It is in Europe.", +]; + +let output = model.predict( & sentences); ``` Output: