🚀 LLMLingua-2-Bert-base-Multilingual-Cased-MeetingBank
本模型在論文 LLMLingua-2: Data Distillation for Efficient and Faithful Task-Agnostic Prompt Compression (Pan 等人, 2024) 中被提出。它是一個基於 BERT 多語言基礎模型(區分大小寫) 微調得到的模型,用於執行與任務無關的提示壓縮的標記分類任務。每個標記 $x_i$
的保留概率 $p_{preserve}$
被用作壓縮的度量標準。該模型在 抽取式文本壓縮數據集 上進行訓練,此數據集是使用 LLMLingua-2 中提出的方法構建的,以 MeetingBank (Hu 等人, 2023) 中的訓練示例作為種子數據。
你可以使用 此數據集 在下游任務(如問答(QA)和會議記錄壓縮後的摘要生成)上評估該模型。
更多詳細信息,請查看 LLMLingua-2 和 LLMLingua 系列 的項目頁面。
🚀 快速開始
本模型基於 BERT 多語言基礎模型微調,用於任務無關的提示壓縮,可在問答、摘要生成等下游任務中評估使用。
💻 使用示例
基礎用法
from llmlingua import PromptCompressor
compressor = PromptCompressor(
model_name="microsoft/llmlingua-2-bert-base-multilingual-cased-meetingbank",
use_llmlingua2=True
)
original_prompt = """John: So, um, I've been thinking about the project, you know, and I believe we need to, uh, make some changes. I mean, we want the project to succeed, right? So, like, I think we should consider maybe revising the timeline.
Sarah: I totally agree, John. I mean, we have to be realistic, you know. The timeline is, like, too tight. You know what I mean? We should definitely extend it.
"""
results = compressor.compress_prompt_llmlingua2(
original_prompt,
rate=0.6,
force_tokens=['\n', '.', '!', '?', ','],
chunk_end_tokens=['.', '\n'],
return_word_label=True,
drop_consecutive=True
)
print(results.keys())
print(f"Compressed prompt: {results['compressed_prompt']}")
print(f"Original tokens: {results['origin_tokens']}")
print(f"Compressed tokens: {results['compressed_tokens']}")
print(f"Compression rate: {results['rate']}")
word_sep = "\t\t|\t\t"
label_sep = " "
lines = results["fn_labeled_original_prompt"].split(word_sep)
annotated_results = []
for line in lines:
word, label = line.split(label_sep)
annotated_results.append((word, '+') if label == '1' else (word, '-'))
print("Annotated results:")
for word, label in annotated_results[:10]:
print(f"{word} {label}")
📄 許可證
本項目採用 Apache-2.0 許可證。