UranusSeven / llama_generative_agent

A generative agent implementation for LLaMA based models, derived from langchain's implementation.
Apache License 2.0
174 stars 15 forks source link

Problems with replacing Chinese models #8

Open wanghao-007 opened 1 year ago

wanghao-007 commented 1 year ago

I found a llama model weight using Chinese training, and I re-wrote the Chinese prompt according to the prompt format, but there is no information output, I would like to ask what is wrong with this situation?

Entering new LLMChain chain... Prompt after formatting: 一个用户和一个人工智能助手之间的聊天。该助手对用户的问题给予帮助、详细和礼貌的回答。

用户: 根据以下输入总结出佩妮的核心特点。如果你不知道,请不要编造。不要返回一个列表。

输入:

助手:

Finished chain. 姓名: 佩妮 (年龄: 25) 初始特征: 外向、友好、有同情心、有主见、有决心 抱歉,您没有提供任何关于佩妮的信息。请提供更多信息以回答您的问题。

UranusSeven commented 1 year ago

The response you posted is actually what we expect. Since your prompt doesn't have any information about Penny, the agent is not able to summrize her core characteristics. Thus, 抱歉,您没有提供任何关于佩妮的信息。请提供更多信息以回答您的问题。 is a correct answer.

Here's ChatGPT's answer without any input:

# The current "Summary" of a character can't be made because the agent hasn't made
# any observations yet.
print(tommie.get_summary())
Name: Tommie (age: 25)
Innate traits: anxious, likes design, talkative
No statements were provided about Tommie's core characteristics.

ref: https://python.langchain.com/en/latest/use_cases/agent_simulations/characters.html

Miao-WangHao commented 1 year ago

The response you posted is actually what we expect. Since your prompt doesn't have any information about Penny, the agent is not able to summrize her core characteristics. Thus, 抱歉,您没有提供任何关于佩妮的信息。请提供更多信息以回答您的问题。 is a correct answer.

Here's ChatGPT's answer without any input:

# The current "Summary" of a character can't be made because the agent hasn't made
# any observations yet.
print(tommie.get_summary())
Name: Tommie (age: 25)
Innate traits: anxious, likes design, talkative
No statements were provided about Tommie's core characteristics.

ref: https://python.langchain.com/en/latest/use_cases/agent_simulations/characters.html

Yes, your tips helped me a lot, and the url you gave me was very useful. Following the last question, I continued to add some memory to the agent. Then I reported an error when doing summary, showing that the importance score was -10. I didn't understand why there was a negative number.

Entering new LLMChain chain... Prompt after formatting: 在1到10的范围内,1是不重要的(例如,刷牙,走路,整理床铺),10是非常重要的(例如,分手,大学录取,生命,灾难),请给下面这段记忆的重要性打分。你必须返回一个正整数。 记忆: 在我小时候发生了严重车祸,差点失去生命 得分: 9 记忆: 在我15岁那年骑自行车摔断了胳膊 分数: 8 记忆: 在我23岁时遇到了我的妻子 得分: 7 记忆: 高中毕业后我拿到了大学录取通知书 分数: 7 记忆: 大学毕业后我找了一份好工作 得分: 6 记忆: 在2022年,我参观了意大利 分数: 5 记忆: 我早上出门忘记吃早饭 得分: 4 记忆: 我今天穿的衣服不好看 分数: 3 记忆: 我今天出门前没有叠被子 分数: 2 记忆: 我有的时候会忘记刷牙 分数: 1 记忆: 佩妮最初来自内布拉斯加的一个小镇,为了追求她成为演员的梦想,她搬到了加州。 分数: Llama.generate: prefix-match hit 重要性分数: -10

Finished chain.

ValueError Traceback (most recent call last) Cell In[5], line 54 20 tommie_observations = [ 21 "佩妮最初来自内布拉斯加的一个小镇,为了追求她成为演员的梦想,她搬到了加州。", 22 "佩妮在芝士蛋糕工厂担任服务员,她从事这份工作是为了在追求她的演艺事业时维持生计。", (...) 51 "别再这么难搞了。这是佩妮在谢尔顿固执或不合作时使用的一句话,往往是面对他觉得不舒服的社交场合。" 52 ] 53 for observation in tommie_observations: ---> 54 tommie.memory.add_memory(observation)

File ~/anaconda3/envs/gpt/lib/python3.10/site-packages/langchain/experimental/generative_agents/memory.py:120, in GenerativeAgentMemory.add_memory(self, memory_content) 118 def add_memory(self, memory_content: str) -> List[str]: 119 """Add an observation or memory to the agent's memory.""" --> 120 importance_score = self._score_memory_importance(memory_content) # 获得重要性分数 121 self.aggregate_importance += importance_score # 重要性分数累加 122 document = Document(page_content=memory_content, metadata={"重要性": importance_score})

File ~/work-miao/llama_generative_agent-main/generative_agents/llama_memory.py:63, in LlamaGenerativeAgentMemory._score_memory_importance(self, memory_content) 61 match = re.search(r"^\D(\d+)", score) 62 if match: ---> 63 return (float(score[0]) / 10) self.importance_weight 64 else: 65 return 0.0

ValueError: could not convert string to float: '-'

UranusSeven commented 1 year ago

The response you posted is actually what we expect. Since your prompt doesn't have any information about Penny, the agent is not able to summrize her core characteristics. Thus, 抱歉,您没有提供任何关于佩妮的信息。请提供更多信息以回答您的问题。 is a correct answer.

Here's ChatGPT's answer without any input:


# The current "Summary" of a character can't be made because the agent hasn't made

# any observations yet.

print(tommie.get_summary())

Name: Tommie (age: 25)

Innate traits: anxious, likes design, talkative

No statements were provided about Tommie's core characteristics.

ref: https://python.langchain.com/en/latest/use_cases/agent_simulations/characters.html

Yes, your tips helped me a lot, and the url you gave me was very useful. Following the last question, I continued to add some memory to the agent. Then I reported an error when doing summary, showing that the importance score was -10. I didn't understand why there was a negative number.

Entering new LLMChain chain...

Prompt after formatting:

在1到10的范围内,1是不重要的(例如,刷牙,走路,整理床铺),10是非常重要的(例如,分手,大学录取,生命,灾难),请给下面这段记忆的重要性打分。你必须返回一个正整数。

记忆: 在我小时候发生了严重车祸,差点失去生命

得分: 9

记忆: 在我15岁那年骑自行车摔断了胳膊

分数: 8

记忆: 在我23岁时遇到了我的妻子

得分: 7

记忆: 高中毕业后我拿到了大学录取通知书

分数: 7

记忆: 大学毕业后我找了一份好工作

得分: 6

记忆: 在2022年,我参观了意大利

分数: 5

记忆: 我早上出门忘记吃早饭

得分: 4

记忆: 我今天穿的衣服不好看

分数: 3

记忆: 我今天出门前没有叠被子

分数: 2

记忆: 我有的时候会忘记刷牙

分数: 1

记忆: 佩妮最初来自内布拉斯加的一个小镇,为了追求她成为演员的梦想,她搬到了加州。

分数:

Llama.generate: prefix-match hit

重要性分数: -10

Finished chain.


ValueError Traceback (most recent call last)

Cell In[5], line 54

 20 tommie_observations = [

 21     "佩妮最初来自内布拉斯加的一个小镇,为了追求她成为演员的梦想,她搬到了加州。",

 22     "佩妮在芝士蛋糕工厂担任服务员,她从事这份工作是为了在追求她的演艺事业时维持生计。",

(...)

 51     "别再这么难搞了。这是佩妮在谢尔顿固执或不合作时使用的一句话,往往是面对他觉得不舒服的社交场合。"

 52 ]

 53 for observation in tommie_observations:

---> 54 tommie.memory.add_memory(observation)

File ~/anaconda3/envs/gpt/lib/python3.10/site-packages/langchain/experimental/generative_agents/memory.py:120, in GenerativeAgentMemory.add_memory(self, memory_content)

118 def add_memory(self, memory_content: str) -> List[str]:

119     """Add an observation or memory to the agent's memory."""

--> 120 importance_score = self._score_memory_importance(memory_content) # 获得重要性分数

121     self.aggregate_importance += importance_score   # 重要性分数累加

122     document = Document(page_content=memory_content, metadata={"重要性": importance_score})

File ~/work-miao/llama_generative_agent-main/generative_agents/llama_memory.py:63, in LlamaGenerativeAgentMemory._score_memory_importance(self, memory_content)

 61 match = re.search(r"^\D*(\d+)", score)

 62 if match:

---> 63 return (float(score[0]) / 10) * self.importance_weight

 64 else:

 65     return 0.0

ValueError: could not convert string to float: '-'

Seems to be an unexpected random problem. It happens sometimes. Probably because the model is not smart enough. My suggestion is to rerun the chain for a correct result.