mirror of
https://github.com/guillaume-be/rust-bert.git
synced 2024-09-11 12:55:34 +03:00
* Fixed Clippy warnings
* Revert "Shallow clone optimization (#243)"
This reverts commit ba584653bc
.
* updated dependencies
* tryouts
* GPT2 tryouts
* WIP GPT2
* input mapping
* Cache storage
* Initial GPT2 prototype
* Initial ONNX Config and decoder implementation
* ONNXDecoder first draft
* Use Decoders in example
* Automated tch-ort conversion, decoder implementation
* ONNXCausalDecoder implementation
* Refactored _get_var_store to be optional, added get_device to gen trait
* updated example
* Added decoder_start_token_id to ConfigOption
* Addition of ONNXModelConfig, make max_position_embeddigs optional
* Addition of forward pass function for ONNXModel
* Working ONNX causal decoder
* Simplify tensor conversion
* refactor translation to facilitate ONNX integration
* Implementation of ONNXEncoder
* Implementation of ONNXConditionalGenerator
* working ONNXCausalGenerator
* - Reworked model resources type for pipelines and generators
* Aligned ONNXConditionalGenerator with other generators to use GenerateConfig for creation
* Moved force_token_id_generation to common utils function, fixed tests, Translation implementation
* generalized forced_bos and forced_eos tokens generation
* Aligned the `encode_prompt_text` method across language models
* Fix prompt encoding for causal generation
* Fix prompt encoding for causal generation
* Support for ONNX models for SequenceClassification
* Support for ONNX models for TokenClassification
* Support for ONNX models for POS and NER pipelines
* Support for ONNX models for ZeroShotClassification pipeline
* Support for ONNX models for QuestionAnswering pipeline
* Support for ONNX models for MaskedLM pipeline
* Added token_type_ids , updated layer cache i/o parsing for ONNX pipelines
* Support for ONNX models for TextGenerationPipeline, updated examples for remote resources
* Remove ONNX zero-shot classification example (lack of correct pretrained model)
* Addition of tests for ONNX pipelines support
* Made onnx feature optional
* Fix device lookup with onnx feature enabled
* Updates from main branch
* Flexible tokenizer creation for M2M100 (NLLB support), make NLLB test optional du to their size
* Fixed Clippy warnings
* Addition of documentation for ONNX
* Added documentation for ONNX support
* upcoming tch 1.12 fixes
* Fix merge conflicts
* Fix merge conflicts (2)
* Add download libtorch feature to ONNX tests
* Add download-onnx feature
* attempt to enable onnx download
* add remote resources feature
* onnx download
* pin ort version
* Update ort version
64 lines
4.1 KiB
Rust
64 lines
4.1 KiB
Rust
// Copyright 2019-present, the HuggingFace Inc. team, The Google AI Language Team and Facebook, Inc.
|
||
// Copyright 2019 Guillaume Becquin
|
||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||
// you may not use this file except in compliance with the License.
|
||
// You may obtain a copy of the License at
|
||
// http://www.apache.org/licenses/LICENSE-2.0
|
||
// Unless required by applicable law or agreed to in writing, software
|
||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
// See the License for the specific language governing permissions and
|
||
// limitations under the License.
|
||
|
||
extern crate anyhow;
|
||
|
||
use rust_bert::pipelines::common::{ModelResource, ModelType};
|
||
use rust_bert::pipelines::summarization::{SummarizationConfig, SummarizationModel};
|
||
use rust_bert::resources::RemoteResource;
|
||
use rust_bert::t5::{T5ConfigResources, T5ModelResources, T5VocabResources};
|
||
|
||
fn main() -> anyhow::Result<()> {
|
||
let config_resource = RemoteResource::from_pretrained(T5ConfigResources::T5_SMALL);
|
||
let vocab_resource = RemoteResource::from_pretrained(T5VocabResources::T5_SMALL);
|
||
let weights_resource = RemoteResource::from_pretrained(T5ModelResources::T5_SMALL);
|
||
|
||
let summarization_config = SummarizationConfig::new(
|
||
ModelType::T5,
|
||
ModelResource::Torch(Box::new(weights_resource)),
|
||
config_resource,
|
||
vocab_resource,
|
||
None,
|
||
);
|
||
let summarization_model = SummarizationModel::new(summarization_config)?;
|
||
|
||
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 \
|
||
habitable zone — not too hot and not too cold for liquid water to exist. The Montreal team, led by Björn Benneke, \
|
||
used data from the NASA's Hubble telescope to assess changes in the light coming from K2-18b's star as the planet \
|
||
passed between it and Earth. They found that certain wavelengths of light, which are usually absorbed by water, \
|
||
weakened when the planet was in the way, indicating not only does K2-18b have an atmosphere, but the atmosphere \
|
||
contains water in vapour form. The team from UCL then analyzed the Montreal team's data using their own software \
|
||
and confirmed their conclusion. This was not the first time scientists have found signs of water on an exoplanet, \
|
||
but previous discoveries were made on planets with high temperatures or other pronounced differences from Earth. \
|
||
\"This is the first potentially habitable planet where the temperature is right and where we now know there is water,\" \
|
||
said UCL astronomer Angelos Tsiaras. \"It's the best candidate for habitability right now.\" \"It's a good sign\", \
|
||
said Ryan Cloutier of the Harvard–Smithsonian Center for Astrophysics, who was not one of either study's authors. \
|
||
\"Overall,\" he continued, \"the presence of water in its atmosphere certainly improves the prospect of K2-18b being \
|
||
a potentially habitable planet, but further observations will be required to say for sure. \" \
|
||
K2-18b was first identified in 2015 by the Kepler space telescope. It is about 110 light-years from Earth and larger \
|
||
but less dense. Its star, a red dwarf, is cooler than the Sun, but the planet's orbit is much closer, such that a year \
|
||
on K2-18b lasts 33 Earth days. According to The Guardian, astronomers were optimistic that NASA's James Webb space \
|
||
telescope — scheduled for launch in 2021 — and the European Space Agency's 2028 ARIEL program, could reveal more \
|
||
about exoplanets like K2-18b."];
|
||
|
||
// Credits: WikiNews, CC BY 2.5 license (https://en.wikinews.org/wiki/Astronomers_find_water_vapour_in_atmosphere_of_exoplanet_K2-18b)
|
||
let _output = summarization_model.summarize(&input);
|
||
for sentence in _output {
|
||
println!("{sentence}");
|
||
}
|
||
|
||
Ok(())
|
||
}
|