cointegrated / rubert-tiny2-sentence-compression

huggingface.co
Total runs: 51
24-hour runs: 2
7-day runs: 14
30-day runs: 37
Model's Last Updated: March 17 2023
token-classification

Introduction of rubert-tiny2-sentence-compression

Model Details of rubert-tiny2-sentence-compression

This model can be used for sentence compression (aka extractive sentence summarization).

It predicts for each word, whether the word can be dropped from the sentence without severely affecting its meaning.

The resulting sentences are often ungrammatical, but they still can be useful.

The model is rubert-tiny2 fine-tuned on the dataset from the paper Sentence compression for Russian: dataset and baselines (the data can be found here ).

Example usage:

import torch
from transformers import AutoModelForTokenClassification, AutoTokenizer
model_name = 'cointegrated/rubert-tiny2-sentence-compression'
model = AutoModelForTokenClassification.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)


def compress(text, threshold=0.5, keep_ratio=None):
    """ Compress a sentence by removing the least important words.
    Parameters:
        threshold: cutoff for predicted probabilities of word removal
        keep_ratio: proportion of words to preserve
    By default, threshold of 0.5 is used.
    """
    with torch.inference_mode():
        tok = tokenizer(text, return_tensors='pt').to(model.device)
        proba = torch.softmax(model(**tok).logits, -1).cpu().numpy()[0, :, 1]
    if keep_ratio is not None:
        threshold = sorted(proba)[int(len(proba) * keep_ratio)]
    kept_toks = []
    keep = False
    prev_word_id = None
    for word_id, score, token in zip(tok.word_ids(), proba, tok.input_ids[0]):
        if word_id is None:
            keep = True
        elif word_id != prev_word_id:
            keep = score < threshold
        if keep:
            kept_toks.append(token)
        prev_word_id = word_id
    return tokenizer.decode(kept_toks, skip_special_tokens=True)


text = 'Кроме того, можно взять идею, рожденную из сердца, и выразить ее в рамках одной '\
    'из этих структур, без потери искренности идеи и смысла песни.'
    
print(compress(text))
print(compress(text, threshold=0.3))
print(compress(text, threshold=0.1))
# можно взять идею, рожденную из сердца, и выразить ее в рамках одной из этих структур.
# можно взять идею, рожденную из сердца выразить ее в рамках одной из этих структур.
# можно взять идею рожденную выразить структур.

print(compress(text, keep_ratio=0.5))
# можно взять идею, рожденную из сердца выразить ее в рамках структур.

Runs of cointegrated rubert-tiny2-sentence-compression on huggingface.co

51
Total runs
2
24-hour runs
3
3-day runs
14
7-day runs
37
30-day runs

More Information About rubert-tiny2-sentence-compression huggingface.co Model

rubert-tiny2-sentence-compression huggingface.co

rubert-tiny2-sentence-compression huggingface.co is an AI model on huggingface.co that provides rubert-tiny2-sentence-compression's model effect (), which can be used instantly with this cointegrated rubert-tiny2-sentence-compression model. huggingface.co supports a free trial of the rubert-tiny2-sentence-compression model, and also provides paid use of the rubert-tiny2-sentence-compression. Support call rubert-tiny2-sentence-compression model through api, including Node.js, Python, http.

rubert-tiny2-sentence-compression huggingface.co Url

https://huggingface.co/cointegrated/rubert-tiny2-sentence-compression

cointegrated rubert-tiny2-sentence-compression online free

rubert-tiny2-sentence-compression huggingface.co is an online trial and call api platform, which integrates rubert-tiny2-sentence-compression's modeling effects, including api services, and provides a free online trial of rubert-tiny2-sentence-compression, you can try rubert-tiny2-sentence-compression online for free by clicking the link below.

cointegrated rubert-tiny2-sentence-compression online free url in huggingface.co:

https://huggingface.co/cointegrated/rubert-tiny2-sentence-compression

rubert-tiny2-sentence-compression install

rubert-tiny2-sentence-compression is an open source model from GitHub that offers a free installation service, and any user can find rubert-tiny2-sentence-compression on GitHub to install. At the same time, huggingface.co provides the effect of rubert-tiny2-sentence-compression install, users can directly use rubert-tiny2-sentence-compression installed effect in huggingface.co for debugging and trial. It also supports api for free installation.

rubert-tiny2-sentence-compression install url in huggingface.co:

https://huggingface.co/cointegrated/rubert-tiny2-sentence-compression

Url of rubert-tiny2-sentence-compression

rubert-tiny2-sentence-compression huggingface.co Url

Provider of rubert-tiny2-sentence-compression huggingface.co

cointegrated
ORGANIZATIONS

Other API from cointegrated