🚀 潛在循環深度語言模型
潛在循環深度語言模型(LRD - LM)是一種實驗性的文本生成架構,旨在通過迭代的潛在處理來捕捉更深層次的上下文信息。它無需生成冗長的思維鏈序列,而是在多次循環迭代中優化其內部狀態,從而在保持適度參數數量的同時,提高文本生成質量。
🚀 快速開始
可以通過集成的 generate()
方法使用該模型進行文本生成,該方法允許你控制最大序列長度、循環迭代次數、溫度和前 k 過濾等參數。
✨ 主要特性
- 深度上下文捕捉:通過迭代的潛在處理,捕捉更深層次的上下文信息。
- 參數適度:在保持適度參數數量的同時,提高文本生成質量。
- 靈活控制:可通過
generate()
方法靈活控制文本生成的參數。
📦 安裝指南
文檔未提及具體安裝步驟,故跳過。
💻 使用示例
基礎用法
from transformers import AutoModelForCausalLM, AutoTokenizer, AutoModel
model = AutoModelForCausalLM.from_pretrained("codewithdark/latent-recurrent-depth-lm")
tokenizer = AutoTokenizer.from_pretrained("codewithdark/latent-recurrent-depth-lm")
prompt = "In the realm of language modeling"
input_ids = tokenizer(prompt, return_tensors='pt').input_ids
logits = model(input_ids, num_iterations=3)
import torch
probs = torch.softmax(logits[:, -1, :], dim=-1)
next_token = torch.multinomial(probs, num_samples=1)
generated_ids = torch.cat([input_ids, next_token], dim=1)
generated_text = tokenizer.decode(generated_ids[0], skip_special_tokens=True)
clean_text = generated_text.replace('Ġ','')
print(generated_text)
高級用法
from transformers import AutoTokenizer, AutoModel, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("codewithdark/latent-recurrent-depth-lm")
model = AutoModel.from_pretrained("codewithdark/latent-recurrent-depth-lm", trust_remote_code=True)
prompt = "In the realm of language modeling"
input_ids = tokenizer(prompt, return_tensors="pt").input_ids
generated_ids = model.generate(input_ids, max_length=50, num_iterations=10, temperature=0.5, top_k=50)
generated_text = tokenizer.decode(generated_ids[0], skip_special_tokens=True)
clean_text = generated_text.replace('Ġ','')
print(clean_text)
📚 詳細文檔
架構
該模型圍繞三個關鍵組件構建:
- 前奏塊(Prelude Block):該塊通過嵌入輸入標記並應用帶有位置編碼的自注意力機制來處理初始處理。
- 循環塊(Recurrent Block):一個核心的、權重共享的塊,用於迭代地優化潛在狀態。通過反覆處理前奏塊的輸出及其自身不斷演變的狀態,模型可以有效地“思考”輸入,而無需輸出中間標記。
- 尾聲塊(Coda Block):最後一個塊將優化後的潛在狀態解碼為輸出標記概率。
應用與侷限性
預期用途
- 文本生成:生成創意文本、對話、代碼或其他自然語言內容。
- 研究:作為探索語言建模中新型架構和技術的試驗檯。
侷限性
- 數據限制:在 Wikitext - 2 - raw - v1 數據集的一小部分(前 1000 個樣本)上進行訓練,與在更大語料庫上訓練的模型相比,其性能可能受到限制。
- 性能:雖然它展示了潛在循環深度的潛力,但其整體性能仍處於實驗階段,可能無法與最先進的模型相媲美。
- 計算開銷:迭代處理會引入額外的計算。
- 偏差:與所有語言模型一樣,生成的輸出可能反映訓練數據中存在的偏差。
訓練細節
該模型在 Wikitext - 2 - raw - v1 數據集的一個子集(前 1000 個樣本)上使用 AdamW 優化器和餘弦退火學習率調度器進行了微調。訓練配置和超參數在隨附的代碼中提供,可能需要進行調整以提高性能。
倫理考慮
該模型旨在用於研究和實驗。用戶在部署或進一步開發這項技術時,必須確保其符合倫理應用,並仔細考慮潛在的偏差和濫用問題。
🔧 技術細節
模型在 Wikitext - 2 - raw - v1 數據集的子集上進行微調,使用 AdamW 優化器和餘弦退火學習率調度器。通過迭代的潛在處理,在多次循環迭代中優化內部狀態,以捕捉更深層次的上下文信息。
📄 許可證
本項目採用 MIT 許可證。