MimicSolver更新过程!🐡

MimicSolver更新过程

1.修改json文件

以SceneCombination为例,分别修改:

该例为新增路径:APText—-SceneCombination—-OutputSolution

2.修改主函数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from mimic import UserConfig, SolvingEngine, MimicConfig

if __name__ == "__main__":

start_path = "D:/Python/MimicSolver/tests/usage/start.yaml"
user_cfg = UserConfig(start_path)

mimicConfig = MimicConfig()

solving_engine = SolvingEngine(mimicConfig)

feed_input_ap = {
"text": "有一堆黄沙,先运走18吨,剩下的用7辆车运完,每车运6吨,这堆黄沙共有多少吨?",
"expression": "x=18+6*7"
}

solving_engine.run(feed_input_ap)

# 深拷贝来解决获取对象参数改变,列表内容同时改变的情况
result = solving_engine.get_solving_result()
for key, value in result.items():
if value != [] and value != "" and value != {}:
print(key, value)

1.重点修改feed_input_ap。且字典的key值应在SharedStateData的属性中

3.修改MimicConfig

4.新增state

5.修改其他state的decide

6.修改state/init.py

7.新增transit

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class APTextToSceneCombination(Transit):
transit_name: str = "APTextToSceneCombination"

def __init__(self):
super().__init__()

def _check(self, transitors: List[str]) -> None:
"""
Executes the transit check, checking whether all transitors have been defined.
:param transitors:
:raises AssertionError: If operation has no predecessors.
"""
functions = [
fn_name
for fn_name, _ in inspect.getmembers(
APTextToSceneCombination, predicate=inspect.isfunction
)
]
for t in transitors:
if t not in functions:
raise ValueError("transitors %s has not defined".format(t))

def scene_reasoning(self, shared_state_data: SharedStateData):
sentence= shared_state_data.text
model_path1 = 'D:/Python/MimicSolver/dl_model/trained_model/scene_trm/best_model1.pth'
model_path2 = 'D:/Python/MimicSolver/dl_model/trained_model/scene_trm/best_model2.pth'

result1 = predict_scene_trm1(sentence, model_path1)
result2 = predict_scene_trm2(sentence, model_path2)

print(result1,result2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class SceneCombinationToOutputSolution(Transit):
transit_name: str = "SceneCombinationToOutputSolution"

def __init__(self):
super().__init__()

def _check(self, transitors: List[str]) -> None:
"""
Executes the transit check, checking whether all transitors have been defined.
:param transitors:
:raises AssertionError: If operation has no predecessors.
"""
functions = [
fn_name
for fn_name, _ in inspect.getmembers(
SceneCombinationToOutputSolution, predicate=inspect.isfunction
)
]
for t in transitors:
if t not in functions:
raise ValueError("transitors %s has not defined".format(t))

def scene_compute(self, shared_state_data: SharedStateData):

print("scene_compute")

1.修改check

2.修改transit类中的具体执行函数,改成对应的的transit名字

8.修改transit/init.py

9.修改core/init.py

10.修改ShareStateData

如需新增状态,则修改


MimicSolver更新过程!🐡
https://yangchuanzhi20.github.io/2024/03/30/人工智能/NLP/项目实战/MWP/MimicSolver/MimicSolver更新过程/
作者
白色很哇塞
发布于
2024年3月30日
许可协议