Stanford_LLM_Tutor
1.0.0
该存储库包含通过拥抱脸部使用变压器模型( gpt2 )构建的AI机器人的实现。聊天机器人利用faiss进行矢量数据库存储,以有效地将用户查询与相关数据匹配。用于培训和响应生成的数据是从官方的Stanford LLM课程中删除的。
gpt2模型。数据刮擦:数据是从斯坦福大学LLM课程的各种讲座中删除的。 h2 , h3和<strong>标签用作密钥,相应的内容分为段落,表,链接,方程式,有序列表和无序列表。
向量数据库(FAISS) :使用L2距离将键存储在FAISS矢量数据库中,以有效检索。当收到用户查询时,Faiss会根据向量相似性找到最接近的匹配键。
提示生成:聊天机器人使用FAISS检索的数据构建一个结构化提示。该提示包括段落,表,方程式,链接,有序列表和与匹配密钥相关的无序列表。
响应生成:构造的提示被馈入GPT-2模型,以生成对用户查询的连贯和相关的响应。
从斯坦福大学LLM课程讲座中刮除的数据具有以下模式:
key1:{
{
'paragraphs': [],
'tables': [],
'links': [],
'equations': [],
'ordered_lists': [],
'unordered_lists': []
} }
key2:{
{
'paragraphs': [],
'tables': [],
'links': [],
'equations': [],
'ordered_lists': [],
'unordered_lists': []
} }
每个键对应于讲座页面的h2 , h3或<strong>标签。与每个密钥关联的数据包括段落,表,链接,方程式,有序列表以及如果存在的无序列表。
用户查询:“有什么好处和危害?”
FAISS检索:使用L2距离将查询与矢量数据库中最接近的键匹配。
及时施工:
# Create a structured prompt
prompt = f"**Question:** {query}nn"
# Add top 2 matched sections
prompt += f"**Sections:**n- {result_key1}n- {result_key2}nn"
# Add content to the prompt
for result_key, result_content in [(result_key1, result_content1), (result_key2, result_content2)]:
if result_content.get('paragraphs'):
prompt += "**Paragraphs:**n" + "n".join(result_content['paragraphs']) + "nn"
if result_content.get('ordered_lists'):
prompt += "**Ordered Lists:**n" + "n".join(["n".join(ol) for ol in result_content['ordered_lists']]) + "nn"
if result_content.get('unordered_lists'):
prompt += "**Unordered Lists:**n" + "n".join(["n".join(ul) for ul in result_content['unordered_lists']]) + "nn"
if result_content.get('tables'):
prompt += "**Tables:**n" + "n".join(["n".join(table) for table in result_content['tables']]) + "nn"
if result_content.get('links'):
prompt += "**Links:**n" + "n".join(result_content['links']) + "nn"
if result_content.get('equations'):
prompt += "**Equations:**n" + "n".join(result_content['equations']) + "nn"
# Add a closing statement
prompt += "Answer is :"
# Define max_length
max_length = min(len(prompt) + 100, 750)
# Generate response
response = generator(prompt[:750], max_length=max_length, num_return_sequences=1, truncation=True, pad_token_id=50256)
生成的响应:GPT-2模型使用提示来生成详细的响应。

此屏幕截图显示了一个示例交互,聊天机器人响应了有关LLMS基础知识的用户查询。
该模型使用CPU资源对Kaggle进行了培训。
欢迎捐款!请打开问题或提交拉动请求,以进行任何改进或新功能。
该项目已根据MIT许可获得许可。有关详细信息,请参见许可证文件。