Mrebel Large
REDFM是REBEL的多語言版本,用於多語言關係抽取任務,支持18種語言的關係三元組提取。
下載量 573
發布時間 : 6/12/2023
模型概述
該模型將關係抽取重新定義為序列到序列的任務,能夠從文本中提取主語-關係-賓語的三元組信息,支持多種語言。
模型特點
多語言支持
支持18種語言的關係抽取,包括英語、中文、西班牙語等主要語言。
序列到序列框架
將關係抽取任務重新定義為序列到序列問題,簡化了傳統流水線方法。
類型化三元組
不僅能提取實體關係,還能識別實體和關係的類型信息。
模型能力
多語言文本分析
關係三元組提取
實體類型識別
跨語言關係抽取
使用案例
知識圖譜構建
自動構建多語言知識圖譜
從多語言文本中提取實體關係,用於構建或擴充知識圖譜。
可自動識別文本中的實體及其關係,形成結構化知識。
信息提取
新聞事件分析
從新聞文本中提取人物、組織、地點之間的關係。
快速理解新聞事件中的關鍵人物和關係網絡。
🚀 REDFM:過濾式多語言關係抽取數據集
REDFM是REBEL的多語言版本。它既可以作為一個獨立的多語言關係抽取系統使用,也可以作為一個預訓練系統,在多語言關係抽取數據集上進行微調。
mREBEL在ACL 2023會議論文RED^{FM}: a Filtered and Multilingual Relation Extraction Dataset中被提出。我們提出了一個新的多語言關係抽取數據集,並訓練了REBEL的多語言版本,該版本將關係抽取重新構建為一個序列到序列(seq2seq)任務。論文可在此處找到。如果您使用了代碼或模型,請在您的論文中引用這項工作:
@inproceedings{huguet-cabot-et-al-2023-redfm-dataset,
title = "RED$^{\rm FM}$: a Filtered and Multilingual Relation Extraction Dataset",
author = "Huguet Cabot, Pere-Llu{\'\i}s and Tedeschi, Simone and Ngonga Ngomo, Axel-Cyrille and
Navigli, Roberto",
booktitle = "Proc. of the 61st Annual Meeting of the Association for Computational Linguistics: ACL 2023",
month = jul,
year = "2023",
address = "Toronto, Canada",
publisher = "Association for Computational Linguistics",
url = "https://arxiv.org/abs/2306.09802",
}
論文的原始代碼倉庫可在此處找到。
請注意,右側的推理小部件不會輸出特殊標記,而這些標記對於區分主語、賓語和關係類型是必需的。有關mREBEL及其預訓練數據集的演示,請查看Spaces演示。
🚀 快速開始
🔧 支持語言
- 阿拉伯語(ar)
- 加泰羅尼亞語(ca)
- 德語(de)
- 希臘語(el)
- 英語(en)
- 西班牙語(es)
- 法語(fr)
- 印地語(hi)
- 意大利語(it)
- 日語(ja)
- 韓語(ko)
- 荷蘭語(nl)
- 波蘭語(pl)
- 葡萄牙語(pt)
- 俄語(ru)
- 瑞典語(sv)
- 越南語(vi)
- 中文(zh)
📦 推理小部件示例
- 文本:Els Red Hot Chili Peppers es van formar a Los Angeles per Kiedis, Flea, el guitarrista Hillel Slovak i el bateria Jack Irons.
- 示例標題:加泰羅尼亞語(Catalan)
📚 推理參數
屬性 | 詳情 |
---|---|
解碼器起始標記ID | 250058 |
源語言 | ca_XX(可根據實際情況修改) |
目標語言 |
🏷️ 標籤
- seq2seq
- relation-extraction
📄 許可證
本模型遵循CC BY - NC - SA 4.0許可證。許可證文本可在此處找到。
📊 任務類型
翻譯(Translation)
📈 數據集
- Babelscape/SREDFM
💻 使用示例
基礎用法
使用pipeline進行關係抽取
from transformers import pipeline
triplet_extractor = pipeline('translation_xx_to_yy', model='Babelscape/mrebel-large', tokenizer='Babelscape/mrebel-large')
# We need to use the tokenizer manually since we need special tokens.
extracted_text = triplet_extractor.tokenizer.batch_decode([triplet_extractor("The Red Hot Chili Peppers were formed in Los Angeles by Kiedis, Flea, guitarist Hillel Slovak and drummer Jack Irons.", decoder_start_token_id=250058, src_lang="en_XX", tgt_lang="<triplet>", return_tensors=True, return_text=False)[0]["translation_token_ids"]]) # change en_XX for the language of the source.
print(extracted_text[0])
# Function to parse the generated text and extract the triplets
def extract_triplets_typed(text):
triplets = []
relation = ''
text = text.strip()
current = 'x'
subject, relation, object_, object_type, subject_type = '','','','',''
for token in text.replace("<s>", "").replace("<pad>", "").replace("</s>", "").replace("tp_XX", "").replace("__en__", "").split():
if token == "<triplet>" or token == "<relation>":
current = 't'
if relation != '':
triplets.append({'head': subject.strip(), 'head_type': subject_type, 'type': relation.strip(),'tail': object_.strip(), 'tail_type': object_type})
relation = ''
subject = ''
elif token.startswith("<") and token.endswith(">"):
if current == 't' or current == 'o':
current = 's'
if relation != '':
triplets.append({'head': subject.strip(), 'head_type': subject_type, 'type': relation.strip(),'tail': object_.strip(), 'tail_type': object_type})
object_ = ''
subject_type = token[1:-1]
else:
current = 'o'
object_type = token[1:-1]
relation = ''
else:
if current == 't':
subject += ' ' + token
elif current == 's':
object_ += ' ' + token
elif current == 'o':
relation += ' ' + token
if subject != '' and relation != '' and object_ != '' and object_type != '' and subject_type != '':
triplets.append({'head': subject.strip(), 'head_type': subject_type, 'type': relation.strip(),'tail': object_.strip(), 'tail_type': object_type})
return triplets
extracted_triplets = extract_triplets_typed(extracted_text[0])
print(extracted_triplets)
使用transformers的模型和分詞器進行關係抽取
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
def extract_triplets_typed(text):
triplets = []
relation = ''
text = text.strip()
current = 'x'
subject, relation, object_, object_type, subject_type = '','','','',''
for token in text.replace("<s>", "").replace("<pad>", "").replace("</s>", "").replace("tp_XX", "").replace("__en__", "").split():
if token == "<triplet>" or token == "<relation>":
current = 't'
if relation != '':
triplets.append({'head': subject.strip(), 'head_type': subject_type, 'type': relation.strip(),'tail': object_.strip(), 'tail_type': object_type})
relation = ''
subject = ''
elif token.startswith("<") and token.endswith(">"):
if current == 't' or current == 'o':
current = 's'
if relation != '':
triplets.append({'head': subject.strip(), 'head_type': subject_type, 'type': relation.strip(),'tail': object_.strip(), 'tail_type': object_type})
object_ = ''
subject_type = token[1:-1]
else:
current = 'o'
object_type = token[1:-1]
relation = ''
else:
if current == 't':
subject += ' ' + token
elif current == 's':
object_ += ' ' + token
elif current == 'o':
relation += ' ' + token
if subject != '' and relation != '' and object_ != '' and object_type != '' and subject_type != '':
triplets.append({'head': subject.strip(), 'head_type': subject_type, 'type': relation.strip(),'tail': object_.strip(), 'tail_type': object_type})
return triplets
# Load model and tokenizer
tokenizer = AutoTokenizer.from_pretrained("Babelscape/mrebel-large", src_lang="en_XX", tgt_lang="tp_XX")
# Here we set English ("en_XX") as source language. To change the source language swap the first token of the input for your desired language or change to supported language. For catalan ("ca_XX") or greek ("el_EL") (not included in mBART pretraining) you need a workaround:
# tokenizer._src_lang = "ca_XX"
# tokenizer.cur_lang_code_id = tokenizer.convert_tokens_to_ids("ca_XX")
# tokenizer.set_src_lang_special_tokens("ca_XX")
model = AutoModelForSeq2SeqLM.from_pretrained("Babelscape/mrebel-large")
gen_kwargs = {
"max_length": 256,
"length_penalty": 0,
"num_beams": 3,
"num_return_sequences": 3,
"forced_bos_token_id": None,
}
# Text to extract triplets from
text = 'The Red Hot Chili Peppers were formed in Los Angeles by Kiedis, Flea, guitarist Hillel Slovak and drummer Jack Irons.'
# Tokenizer text
model_inputs = tokenizer(text, max_length=256, padding=True, truncation=True, return_tensors = 'pt')
# Generate
generated_tokens = model.generate(
model_inputs["input_ids"].to(model.device),
attention_mask=model_inputs["attention_mask"].to(model.device),
decoder_start_token_id = tokenizer.convert_tokens_to_ids("tp_XX"),
**gen_kwargs,
)
# Extract text
decoded_preds = tokenizer.batch_decode(generated_tokens, skip_special_tokens=False)
# Extract triplets
for idx, sentence in enumerate(decoded_preds):
print(f'Prediction triplets sentence {idx}')
print(extract_triplets_typed(sentence))
📄 許可證
本模型遵循CC BY - NC - SA 4.0許可證。許可證文本可在此處找到。
Rebel Large
REBEL是一種基於BART的序列到序列模型,用於端到端關係抽取,支持200多種不同關係類型。
知識圖譜
Transformers 英語

R
Babelscape
37.57k
219
Nel Mgenre Multilingual
基於mGENRE的多語言生成式實體檢索模型,針對歷史文本優化,支持100+種語言,特別適配法語、德語和英語的歷史文檔實體鏈接。
知識圖譜
Transformers 支持多種語言

N
impresso-project
17.13k
2
Biomednlp KRISSBERT PubMed UMLS EL
MIT
KRISSBERT是一個基於知識增強自監督學習的生物醫學實體鏈接模型,通過利用無標註文本和領域知識訓練上下文編碼器,有效解決實體名稱多樣性變異和歧義性問題。
知識圖譜
Transformers 英語

B
microsoft
4,643
29
Coder Eng
Apache-2.0
CODER是一種知識增強型跨語言醫學術語嵌入模型,專注於醫學術語規範化任務。
知識圖譜
Transformers 英語

C
GanjinZero
4,298
4
Umlsbert ENG
Apache-2.0
CODER是一個基於知識注入的跨語言醫學術語嵌入模型,專注於醫學術語標準化任務。
知識圖譜
Transformers 英語

U
GanjinZero
3,400
13
Text2cypher Gemma 2 9b It Finetuned 2024v1
Apache-2.0
該模型是基於google/gemma-2-9b-it微調的Text2Cypher模型,能夠將自然語言問題轉換為Neo4j圖數據庫的Cypher查詢語句。
知識圖譜
Safetensors 英語
T
neo4j
2,093
22
Triplex
Triplex是SciPhi.AI基於Phi3-3.8B微調的模型,專為從非結構化數據構建知識圖譜設計,可將知識圖譜創建成本降低98%。
知識圖譜
T
SciPhi
1,808
278
Genre Linking Blink
GENRE是一種基於序列到序列方法的實體檢索系統,採用微調後的BART架構,通過受約束的束搜索技術生成唯一實體名稱。
知識圖譜 英語
G
facebook
671
10
Text To Cypher Gemma 3 4B Instruct 2025.04.0
Gemma 3.4B IT 是一個基於文本到文本生成的大語言模型,專門用於將自然語言轉換為Cypher查詢語言。
知識圖譜
Safetensors
T
neo4j
596
2
Mrebel Large
REDFM是REBEL的多語言版本,用於多語言關係抽取任務,支持18種語言的關係三元組提取。
知識圖譜
Transformers 支持多種語言

M
Babelscape
573
71
精選推薦AI模型
Llama 3 Typhoon V1.5x 8b Instruct
專為泰語設計的80億參數指令模型,性能媲美GPT-3.5-turbo,優化了應用場景、檢索增強生成、受限生成和推理任務
大型語言模型
Transformers 支持多種語言

L
scb10x
3,269
16
Cadet Tiny
Openrail
Cadet-Tiny是一個基於SODA數據集訓練的超小型對話模型,專為邊緣設備推理設計,體積僅為Cosmo-3B模型的2%左右。
對話系統
Transformers 英語

C
ToddGoldfarb
2,691
6
Roberta Base Chinese Extractive Qa
基於RoBERTa架構的中文抽取式問答模型,適用於從給定文本中提取答案的任務。
問答系統 中文
R
uer
2,694
98