语言:
- 英语
任务标签:
- 句子相似度
标签:
- 句子转换模型
- 特征提取
- 句子相似度
- 转换器
数据集:
- ANLI
- MNLI
- SNLI
sbert-roberta-large-anli-mnli-snli
这是一个基于sentence-transformers的模型:它能将句子和段落映射到一个768维的密集向量空间,可用于聚类或语义搜索等任务。
该模型以RoBERTa-large为权重初始化,并在ANLI(Nie等人,2020)、MNLI(Williams等人,2018)和SNLI(Bowman等人,2015)数据集上,使用training_nli.py
示例脚本进行训练。
训练详情:
使用方法(Sentence-Transformers)
安装sentence-transformers后,使用此模型非常简单:
pip install -U sentence-transformers
然后可以这样使用模型:
from sentence_transformers import SentenceTransformer
sentences = ["这是一个示例句子", "每个句子都会被转换"]
model = SentenceTransformer("usc-isi/sbert-roberta-large-anli-mnli-snli")
embeddings = model.encode(sentences)
print(embeddings)
使用方法(Hugging Face Transformers)
如果不使用sentence-transformers,可以这样使用模型:首先将输入传递给转换器模型,然后对上下文化的词嵌入应用适当的池化操作。
import torch
from transformers import AutoModel, AutoTokenizer
def mean_pooling(model_output, attention_mask):
token_embeddings = model_output[0]
input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
sentences = ["这是一个示例句子", "每个句子都会被转换"]
tokenizer = AutoTokenizer.from_pretrained("usc-isi/sbert-roberta-large-anli-mnli-snli")
model = AutoModel.from_pretrained("usc-isi/sbert-roberta-large-anli-mnli-snli")
encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors="pt")
with torch.no_grad():
model_output = model(**encoded_input)
sentence_embeddings = mean_pooling(model_output, encoded_input["attention_mask"])
print("句子嵌入:")
print(sentence_embeddings)
评估结果
评估结果请参见我们论文的第4.1节。
完整模型架构
SentenceTransformer(
(0): Transformer({'max_seq_length': 128, 'do_lower_case': False}) with Transformer model: RobertaModel
(1): Pooling({'word_embedding_dimension': 768, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False})
)
引用与作者
有关该项目的更多信息,请参阅我们的论文:
Ciosici, Manuel, 等. "Machine-Assisted Script Curation." Proceedings of the 2021 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies: Demonstrations, Association for Computational Linguistics, 2021, pp. 8–17. ACLWeb, https://www.aclweb.org/anthology/2021.naacl-demos.2.
参考文献
- Samuel R. Bowman, Gabor Angeli, Christopher Potts, and Christopher D. Manning. 2015. A large annotated corpus for learning natural language inference. In Proceedings of the 2015 Conference on Empirical Methods in Natural Language Processing, pages 632–642, Lisbon, Portugal. Association for Computational Linguistics.
- Yixin Nie, Adina Williams, Emily Dinan, Mohit Bansal, Jason Weston, and Douwe Kiela. 2020. AdversarialNLI: A new benchmark for natural language understanding. In Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics, pages 4885–4901, Online. Association for Computational Linguistics.
- Adina Williams, Nikita Nangia, and Samuel Bowman. 2018. A broad-coverage challenge corpus for sentence understanding through inference. In Proceedings of the 2018 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long Papers), pages 1112–1122, New Orleans, Louisiana. Association for Computational Linguistics.