PhoRanker / README.md
itdainb's picture
Update README.md
f5476e4 verified
|
raw
history blame
3.13 kB
metadata
language:
  - vi
license: apache-2.0
library_name: sentence-transformers
tags:
  - cross-encoder
  - rerank
datasets:
  - unicamp-dl/mmarco
model-index:
  - name: VietnameseCrossEncoder
    results:
      - task:
          type: text-classification
        dataset:
          name: MMarco (Vi-Dev)
          type: unicamp-dl/mmarco
        metrics:
          - type: NDCG
            value: 0
            name: NDCG@10
            verified: false
          - type: MRR
            value: 0
            name: MRR@10
            verified: false
widget:
  - source_sentence: UIT   ?
    sentences:
      - >-
        UIT là Trường Đại_học Công_nghệ Thông_tin ( ĐH CNTT ) , Đại_học Quốc_gia
        Thành_phố Hồ_Chí_Minh ( ĐHQG - HCM )
      - >-
        Mô_hình rerank — còn được gọi là cross - encoder — là một loại mô_hình
        mà , khi được cung_cấp một cặp truy vấn và tài_liệu , sẽ đưa ra một điểm
        tương_đồng .
      - >-
        Việt_Nam , quốc_hiệu là Cộng_hòa xã_hội chủ_nghĩa Việt_Nam , là một
        quốc_gia xã_hội chủ_nghĩa nằm ở cực Đông của bán_đảo Đông_Dương thuộc
        khu_vực Đông_Nam_Á
pipeline_tag: sentence-similarity

Installation

  • Install pyvi to word segment:

    • pip install pyvi
  • Install sentence-transformers (recommend):

    • pip install sentence-transformers
  • Install transformers (optional):

    • pip install transformers

Pre-processing

from pyvi import ViTokenizer

query = "UIT là gì?"
sentences = [
    "UIT là Trường Đại học Công nghệ Thông tin (ĐH CNTT), Đại học Quốc gia Thành phố Hồ Chí Minh (ĐHQG-HCM)",
    "Mô hình rerank — còn được gọi là cross-encoder — là một loại mô hình mà, khi được cung cấp một cặp truy vấn và tài liệu, sẽ đưa ra một điểm tương đồng.",
    "Việt Nam, quốc hiệu là Cộng hòa xã hội chủ nghĩa Việt Nam, là một quốc gia xã hội chủ nghĩa nằm ở cực Đông của bán đảo Đông Dương thuộc khu vực Đông Nam Á"
]

tokenized_query = ViTokenizer.tokenize(query)
tokenized_sentences = [ViTokenizer.tokenize(sent) for sent in sentences]

tokenized_pairs = [[tokenized_query, sent] for sent in tokenized_sentences]

Usage with sentence-transformers

from sentence_transformers import CrossEncoder
model = CrossEncoder('itdainb/vietnamese-cross-encoder', max_length=256)
scores = model.predict(tokenized_pairs)

Usage with transformers

from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch

model = AutoModelForSequenceClassification.from_pretrained('itdainb/vietnamese-cross-encoder')
tokenizer = AutoTokenizer.from_pretrained('itdainb/vietnamese-cross-encoder')

activation_fct = torch.nn.Identity()

features = tokenizer(tokenized_pairs, padding=True, truncation="longest_first", return_tensors="pt", max_length=256)

model.eval()
with torch.no_grad():
    model_predictions = model(**features, return_dict=True)
    logits = activation_fct(model_predictions.logits)

    scores = [score[0] for score in logits]
    print(scores)