File size: 103,309 Bytes
67068c5 |
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 |
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"150\n"
]
}
],
"source": [
"import json\n",
"ctrl = json.load(open('./ctrl_toolcall_train_v1.6_ch.json'))+json.load(open('./ctrl_toolcall_train_eng_v1.6_update2.json'))\n",
"nav = json.load(open('./nav_toolcall_train_v1.6_ch.json'))+json.load(open('./nav_toolcall_train_eng_v1.6_update2.json'))\n",
"multi_ctrl = json.load(open('./multi_toolcall_train_v1.6_ch.json'))+json.load(open('./multi_toolcall_train_eng_v1.6_update2.json'))\n",
"from collections import defaultdict\n",
"import numpy as np\n",
"funcs = defaultdict(set)\n",
"normal_seat = set([\"SEAT_ROW_1_LEFT\",\"SEAT_ROW_1_RIGHT\",\"SEAT_ROW_2_LEFT\",\"SEAT_ROW_2_RIGHT\",\"SEAT_ROW_3_LEFT\",\n",
"\"SEAT_ROW_3_RIGHT\",\"SEAT_ALL\",\"SEAT_ROW_1\",\"SEAT_ROW_2\",\"SEAT_ROW_3\"])\n",
"for tmp in ctrl:\n",
" for idx,conv in enumerate(tmp['conversations']):\n",
" if conv['from']=='function_call':\n",
" tmp_js = json.loads(conv['value'])[0]\n",
" try:\n",
" if 'areaId' in tmp_js[\"arguments\"] and tmp_js[\"arguments\"]['areaId'] in normal_seat:\n",
" tmp_js[\"arguments\"]['areaId']=\"\"\n",
" if 'areaId' in tmp_js[\"arguments\"]:\n",
" func_type_name = tmp_js[\"arguments\"][\"propertyId\"] if tmp_js[\"arguments\"]['areaId']==\"\" else tmp_js[\"arguments\"][\"propertyId\"]+'%'+tmp_js[\"arguments\"]['areaId']\n",
" if 'value' in tmp_js[\"arguments\"] and not str(tmp_js[\"arguments\"]['value']).isdigit():\n",
" funcs[func_type_name+'%'+tmp_js[\"arguments\"]['value']].add(tmp['conversations'][idx-1]['value'])\n",
" elif 'operation' in tmp_js[\"arguments\"] and tmp_js[\"arguments\"]['operation'] in ['increase','decrease'] and not tmp_js[\"arguments\"][\"propertyId\"] in ['WINDOW_POS']:\n",
" funcs[func_type_name+'%'+tmp_js[\"arguments\"]['operation']].add(tmp['conversations'][idx-1]['value'])\n",
" elif tmp_js[\"arguments\"][\"propertyId\"] in ['POWER_SUNSHADE','WINDOW_POS']:\n",
" func_tmp = func_type_name+\"%\"+tmp_js[\"arguments\"][\"operation\"]\n",
" if 'value' in tmp_js[\"arguments\"]:\n",
" func_tmp+='%'+str(tmp_js[\"arguments\"]['value'])\n",
" funcs[func_tmp].add(tmp['conversations'][idx-1]['value'])\n",
" else:\n",
" funcs[func_type_name].add(tmp['conversations'][idx-1]['value'])\n",
" except:\n",
" if tmp_js['name']==\"set_seat_mode\":\n",
" funcs[tmp_js['name']+'%'+tmp_js[\"arguments\"][\"value\"]].add(tmp['conversations'][idx-1]['value'])\n",
" else:\n",
" funcs[tmp_js['name']].add(tmp_js[\"arguments\"][\"query\"])\n",
"print(len(funcs))"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"multi_ctrl_case = []\n",
"cnt = 0\n",
"ctrl_act = 2\n",
"np.random.shuffle(multi_ctrl)\n",
"for tmp in multi_ctrl:\n",
" for idx,conv in enumerate(tmp['conversations']):\n",
" if conv['from']=='human':\n",
" multi_ctrl_case.append(','.join(conv['value'].split(',')[:ctrl_act]).replace('\"','').replace('Sure! Let me help you with that. ',''))\n",
" cnt+=1\n",
" if cnt+1%100==0: ctrl_act+=1\n",
" if len(multi_ctrl_case)>1500:break"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'dfzsad' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[3], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mdfzsad\u001b[49m\n",
"\u001b[0;31mNameError\u001b[0m: name 'dfzsad' is not defined"
]
}
],
"source": [
"dfzsad"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"id2label = {i:k for i,k in enumerate(sorted(list(funcs.keys()))+['others','multi_ctrl_cases'])}\n",
"label2id = {v: k for k, v in id2label.items()}\n",
"dataset = [{'text':t,\"label\":label2id[k]} for k in funcs for t in funcs[k]]\n",
"other_case = []\n",
"cnt=0\n",
"np.random.shuffle(nav)\n",
"for tmp in nav:\n",
" for idx,conv in enumerate(tmp['conversations']):\n",
" if conv['from']=='human':\n",
" other_case.append(conv['value'])\n",
" cnt+=1\n",
" if cnt>800:break\n",
"other_case+=['窗戶','窗戶好髒','窗戶有髒汙','陽光灑進窗戶。', '窗外風景優美。', '微風吹拂窗簾。', '雨滴打在窗上。', '窗戶倒影清晰。', '打開窗戶通風。', '車窗外景色飛逝。', '車窗結滿霧氣。', '擦拭乾淨車窗。', '搖下車窗吹風。', '窗內光線柔和。', '窗外喧囂吵雜。', '月光透過窗戶。', '窗戶玻璃反光。', '推開窗戶探頭。', '車窗映出人影。', '窗外一片黑暗。', '凝視窗外發呆。', '窗戶結霜模糊。', '窗外雪花飄落。']\n",
"other_case+=['座椅','座位上','座位下','座位','坐在椅子上休息。', '這把椅子很舒適。', '椅子被太陽曬熱。', '這張座椅很寬敞。', '請坐好您的椅子。', '椅子搖晃不穩。', '她拉開了椅子。', '把椅子移過來。', '椅子發出嘎吱聲。', '我坐在辦公椅上。', '這張椅子很重。', '座椅彈性很好。', '請回到您的座位。', '椅子排成一列。', '這張椅子是木製的。', '椅子上鋪著毯子。', '我的座椅很冰冷。', '這張椅子是我的。', '椅子被重新油漆。', '請讓座給老人。']\n",
"other_case+=['風向','冷氣','電風扇正在轉動。', '風扇吹來涼風。', '風扇發出噪音。', '冷氣機滴水。', '風扇吹向我。', '冷氣遙控器不見了。', '風扇吹得很舒服。', '冷氣機壞掉了。', '冷氣口對著我。', '冷氣運轉中。', '冷氣口髒了。', '風扇轉速變慢。', '冷氣濾網很髒。', '冷氣需要清洗。', '風扇的風很涼。']\n",
"other_case+=['墊高','用書本墊高螢幕。', '用枕頭支撐腰部。', '這根柱子支撐屋頂。', '用木塊墊高桌子。', '這塊海綿很支撐。', '請支撐住這個東西。', '用墊子墊高椅子。', '這個架子很支撐。', '用磚塊墊高。', '用手支撐頭部。', '墊高以利通風。', '用椅子墊高雙腳。', '這個床墊很支撐。', '用支架支撐植物。', '用石頭墊高。', '墊高可以看得更清楚。', '這根棍子是支撐。', '用墊子支撐脖子。', '墊高方便取物。']\n",
"other_case+=['生活陷入了循環。', '這個模式很有效。', '打破舊有模式。', '這是個惡性循環。', '建立新的模式。', '每天都在循環。', '這個模式很穩定。', '陷入了疲勞循環。', '學習新的模式。', '這是一種運作模式。', '循環播放音樂。', '這個模式無法更改。', '他習慣了這個模式。', '保持良好循環。', '跳出這個循環。', '找到了新的模式。', '不斷重複的循環。', '這個模式很簡單。']\n",
"other_case+=['電動車非常安靜。', '打開除霜功能。', '電動門緩緩開啟。', '除霜後視野清晰。', '這扇窗戶是電動的。', '電動牙刷很方便。', '除霜需要一些時間。', '電動滑板車。', '電動螺絲起子。', '除霜裝置故障。', '電動百葉窗。', '這輛車是電動的。', '啟動電動功能。', '電動吸塵器。', '電動按摩椅。', '除霜按鈕亮了。', '電動自行車。', '除霜效果很好。']\n",
"other_case+=['再高一點','再低一點']\n",
"other_case+=['fan','air conditioner','AC','sliding door','door','left','right','fuck','window','heat','seat','row','ottoman','second seat','first row']\n",
"other_case+=['window','the window is dirty','the window has dirt','Sunlight streams through the window.', 'The scenery outside the window is beautiful.', 'The breeze rustles the curtains.', 'Raindrops hit the window.', 'The window reflection is clear.', 'Open the window for ventilation.', 'The scenery outside the car window flashes past.', 'The car window is completely fogged up.', 'Wipe the car window clean.', 'Roll down the car window for air.', 'The light inside the window is soft.', 'The outside is noisy.', 'Moonlight through the window.', 'The window glass reflects light.', 'Push open the window and peer out.', 'A reflection of a person appears on the car window.', 'Outside the window is completely dark.', 'Gazing blankly out the window.', 'The window is frosted and blurry.', 'Snowflakes are falling outside the window.']\n",
"other_case+=['seat','on the seat','under the seat','seating','Sitting on a chair to rest.', 'This chair is very comfortable.', 'The chair was heated by the sun.', 'This seat is very spacious.', 'Please sit properly in your chair.', 'The chair is shaky and unstable.', 'She pulled out the chair.', 'Move the chair over.', 'The chair makes a creaking sound.', 'I sit on an office chair.', 'This chair is very heavy.', 'The seat has good elasticity.', 'Please return to your seat.', 'The chairs are lined up in a row.', 'This chair is made of wood.', 'A blanket is spread on the chair.', 'My seat is very cold.', 'This chair is mine.', 'The chair was repainted.', 'Please offer your seat to an elderly person.']\n",
"other_case+=['air direction','air conditioning','The electric fan is turning.', 'The fan is blowing cool air.', 'The fan makes noise.', 'The air conditioner is dripping water.', 'The fan is blowing towards me.', 'The air conditioner remote is missing.', 'The fan is blowing very comfortably.', 'The air conditioner is broken.', 'The air vent is pointed at me.', 'The air conditioner is running.', 'The air vent is dirty.', 'The fan speed slows down.', 'The air conditioner filter is very dirty.', 'The air conditioner needs cleaning.', \"The fan's breeze is very cool.\"]\n",
"other_case+=['raise up','Use books to raise the monitor.', 'Use a pillow to support the lower back.', 'This pillar supports the roof.', 'Use wooden blocks to raise the table.', 'This sponge is very supportive.', 'Please support this item.', 'Use a cushion to raise the chair.', 'This shelf is very supportive.', 'Use bricks to raise up.', 'Use your hand to support your head.', 'Raise up for better ventilation.', 'Use a chair to raise your feet.', 'This mattress is very supportive.', 'Use a stand to support the plant.', 'Use stones to raise up.', 'Raising up allows for clearer viewing.', 'This stick is a support.', 'Use a cushion to support the neck.', 'Raise up for easy access to items.']\n",
"other_case+=['Life has fallen into a loop.', 'This pattern is very effective.', 'Break the old pattern.', 'This is a vicious cycle.', 'Establish a new pattern.', 'It cycles every day.', 'This pattern is very stable.', 'Fell into a cycle of fatigue.', 'Learn a new pattern.', 'This is a mode of operation.', 'Loop playback of music.', 'This pattern cannot be changed.', 'He is used to this pattern.', 'Maintain a good cycle.', 'Jump out of this cycle.', 'Found a new pattern.', 'A constantly repeating cycle.', 'This pattern is very simple.']\n",
"other_case+=['The electric car is very quiet.', 'Turn on the defrost function.', 'The electric door opens slowly.', 'The view is clear after defrosting.', 'This window is electric.', 'Electric toothbrushes are very convenient.', 'Defrosting takes some time.', 'Electric scooter.', 'Electric screwdriver.', 'The defrost device is faulty.', 'Electric blinds.', 'This car is electric.', 'Activate the electric function.', 'Electric vacuum cleaner.', 'Electric massage chair.', 'The defrost button is lit.', 'Electric bicycle.', 'The defrost effect is very good.']\n",
"other_case+=['a little higher','Please turn on the second row on','Please turn on','Please provide the original sentence','I can assist you with paraphrasing it in a more fluent manner','Please provide the original sentence so I can assist you with paraphrasing it in a more fluent manner','a little lower','please','Please provide the sentence you would like me to paraphrase.','sentence you would like me to paraphrase.','ask me to paraphrase.']\n",
"cnt=0\n",
"for tmp in other_case:\n",
" dataset.append({'text':tmp,'label':label2id['others']})\n",
"for tmp in multi_ctrl_case:\n",
" dataset.append({'text':tmp,'label':label2id['multi_ctrl_cases']})\n",
"\n",
"dataset.append({'text':'關閉車窗並開啟辦公模式','label':label2id['multi_ctrl_cases']})\n",
"dataset.append({'text':'開啟空調另外HHTD怎麼報名','label':label2id['multi_ctrl_cases']})\n",
"dataset.append({'text':'結束辦公模式','label':label2id[\"set_seat_mode%OFF\"]})\n",
"dataset.append({'text':'1排結束辦公模式','label':label2id[\"set_seat_mode%OFF\"]})\n",
"dataset.append({'text':'2排結束辦公模式','label':label2id[\"set_seat_mode%OFF\"]})\n",
"dataset.append({'text':'3排結束辦公模式','label':label2id[\"set_seat_mode%OFF\"]})\n",
"dataset.append({'text':'第3排結束辦公模式','label':label2id[\"set_seat_mode%OFF\"]})\n",
"dataset.append({'text':'第2排結束辦公模式','label':label2id[\"set_seat_mode%OFF\"]})\n",
"dataset.append({'text':'第1排結束辦公模式','label':label2id[\"set_seat_mode%OFF\"]})\n",
"dataset.append({'text':'結束休憩模式','label':label2id[\"set_seat_mode%OFF\"]})\n",
"dataset.append({'text':'3排結束休憩模式','label':label2id[\"set_seat_mode%OFF\"]})\n",
"dataset.append({'text':'2排結束休憩模式','label':label2id[\"set_seat_mode%OFF\"]})\n",
"dataset.append({'text':'1排結束休憩模式','label':label2id[\"set_seat_mode%OFF\"]})\n",
"dataset.append({'text':'第1排結束休憩模式','label':label2id[\"set_seat_mode%OFF\"]})\n",
"dataset.append({'text':'第2排結束休憩模式','label':label2id[\"set_seat_mode%OFF\"]})\n",
"dataset.append({'text':'第3排結束休憩模式','label':label2id[\"set_seat_mode%OFF\"]})\n",
"dataset.append({'text':'冷氣不要吹腳','label':label2id[\"HVAC_FAN_DIRECTION%OFF\"]})\n",
"dataset.append({'text':'冷氣不要吹頭','label':label2id[\"HVAC_FAN_DIRECTION%OFF\"]})\n",
"dataset.append({'text':'冷氣不要吹臉','label':label2id[\"HVAC_FAN_DIRECTION%OFF\"]})\n",
"dataset.append({'text':'冷氣不要吹身體','label':label2id[\"HVAC_FAN_DIRECTION%OFF\"]})\n",
"dataset.append({'text':'冷氣不要吹','label':label2id[\"HVAC_FAN_DIRECTION%OFF\"]})\n",
"dataset.append({'text':'冷氣不要吹我','label':label2id[\"HVAC_FAN_DIRECTION%OFF\"]})\n",
"dataset.append({'text':'冷氣出風不要掃風了','label':label2id[\"HVAC_FAN_OUTPUT_MODE%OFF\"]})\n",
"dataset.append({'text':'按摩強度開弱','label':label2id[\"SEAT_MASSAGE_INTENSITY%LOW\"]})\n",
"dataset.append({'text':'按摩強度開低','label':label2id[\"SEAT_MASSAGE_INTENSITY%LOW\"]})\n",
"dataset.append({'text':'按摩強度開中等','label':label2id[\"SEAT_MASSAGE_INTENSITY%MEDIUM\"]})\n",
"dataset.append({'text':'打開内循環','label':label2id[\"HVAC_RECIRC_MODE%INTERNAL\"]})\n",
"dataset.append({'text':'窗戶關小30 percentage','label':label2id[\"WINDOW_POS%decrease%30\"]})\n",
"dataset.append({'text':'溫度有點低','label':label2id[\"HVAC_TEMPERATURE_SET%increase\"]})\n",
"dataset.append({'text':'我溫度有點高','label':label2id[\"HVAC_TEMPERATURE_SET%decrease\"]})\n",
"dataset.append({'text':'冷氣風太小','label':label2id[\"HVAC_FAN_SPEED%increase\"]})\n",
"dataset.append({'text':'風太大吹得不舒服,調小','label':label2id[\"HVAC_FAN_SPEED%decrease\"]})\n",
"dataset.append({'text':'steering wheel heater should be turned off.','label':label2id[\"HVAC_STEERING_WHEEL_HEAT%false\"]})\n",
"dataset.append({'text':'please adjust the car window to about 90 percent open?','label':label2id[\"WINDOW_POS%set%90\"]})\n",
"dataset.append({'text':'Could you please adjust the car window to about 80 percent open?','label':label2id[\"WINDOW_POS%set%80\"]})\n",
"dataset.append({'text':'please adjust the window to about 70 percent open?','label':label2id[\"WINDOW_POS%set%70\"]})\n",
"dataset.append({'text':'Could you please adjust the car window to about 60 percent open?','label':label2id[\"WINDOW_POS%set%60\"]})\n",
"dataset.append({'text':'adjust the window to about 50 percent open?','label':label2id[\"WINDOW_POS%set%50\"]})\n",
"dataset.append({'text':'please adjust the window to about 40 percent open?','label':label2id[\"WINDOW_POS%set%40\"]})\n",
"dataset.append({'text':'Could you please adjust the car window to about 30 percent open?','label':label2id[\"WINDOW_POS%set%30\"]})\n",
"dataset.append({'text':'Could you please adjust the car window to about 20 percent open?','label':label2id[\"WINDOW_POS%set%20\"]})\n",
"dataset.append({'text':'please adjust the window to about 10 percent open?','label':label2id[\"WINDOW_POS%set%10\"]})\n",
"\n",
"dataset.append({'text':'adjust the window to about 90 percent close?','label':label2id[\"WINDOW_POS%set%10\"]})\n",
"dataset.append({'text':'Could you please adjust the car window to about 80 percent close?','label':label2id[\"WINDOW_POS%set%20\"]})\n",
"dataset.append({'text':'Could you please adjust the window to about 70 percent close?','label':label2id[\"WINDOW_POS%set%30\"]})\n",
"dataset.append({'text':'adjust the car window to about 60 percent close?','label':label2id[\"WINDOW_POS%set%40\"]})\n",
"dataset.append({'text':'please adjust the window to about 50 percent close?','label':label2id[\"WINDOW_POS%set%50\"]})\n",
"dataset.append({'text':'Could you please adjust the car window to about 40 percent close?','label':label2id[\"WINDOW_POS%set%60\"]})\n",
"dataset.append({'text':'adjust the car window to about 30 percent close?','label':label2id[\"WINDOW_POS%set%70\"]})\n",
"dataset.append({'text':'please adjust the window to about 20 percent close?','label':label2id[\"WINDOW_POS%set%80\"]})\n",
"dataset.append({'text':'please adjust the window to about 10 percent close?','label':label2id[\"WINDOW_POS%set%90\"]})\n",
"\n",
"\n",
"useful_dataset = []\n",
"for tmp in dataset:\n",
" tmp['text'] = tmp['text'].replace(',','').replace('\"','').replace('Sure! Let me help you with that. ','')\n",
" if len(tmp['text']) < 5 or 'paraphras' in tmp['text'] or 'rephras' in tmp['text'] or 'sentence' in tmp['text']:continue\n",
" useful_dataset.append(tmp)\n",
"json.dump(useful_dataset,open('classifier_data.jsonl','w'),indent=2,ensure_ascii=False)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[2025-10-21 06:09:58,395] [INFO] [real_accelerator.py:219:get_accelerator] Setting ds_accelerator to cuda (auto detect)\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/usr/bin/ld: cannot find -laio: No such file or directory\n",
"collect2: error: ld returned 1 exit status\n",
"/usr/bin/ld: cannot find -laio: No such file or directory\n",
"collect2: error: ld returned 1 exit status\n"
]
}
],
"source": [
"\n",
"\n",
"import torch\n",
"from datasets import load_dataset\n",
"from transformers import AutoTokenizer, AutoModelForSequenceClassification, TrainingArguments, Trainer\n",
"\n",
"def train_bert_classifier():\n",
" num_labels = len(id2label)\n",
" model_name = \"/mnt/jeff/InCar/bert/ModernBERT-base\"\n",
" tokenizer = AutoTokenizer.from_pretrained(model_name)\n",
" model = AutoModelForSequenceClassification.from_pretrained(\n",
" model_name,\n",
" num_labels=num_labels,\n",
" id2label=id2label,\n",
" label2id=label2id\n",
" )\n",
"\n",
" def preprocess_function(examples):\n",
" return tokenizer(examples[\"text\"], truncation=True, padding=True)\n",
"\n",
" print(\"資料前處理中...\")\n",
" dataset = load_dataset('json', data_files='classifier_data.jsonl')\n",
" tokenized_dataset = dataset.map(preprocess_function, batched=True)\n",
"\n",
" split_dataset = tokenized_dataset['train'].train_test_split(test_size=0.1)\n",
" train_dataset = tokenized_dataset['train']\n",
" eval_dataset = split_dataset['test']\n",
"\n",
" training_args = TrainingArguments(\n",
" output_dir=\"./results_classifier3\", # 訓練結果儲存目錄\n",
" learning_rate=2e-5, # 學習率\n",
" per_device_train_batch_size=8, # 訓練批次大小\n",
" per_device_eval_batch_size=8, # 評估批次大小\n",
" num_train_epochs=3, # 訓練 epochs 數\n",
" weight_decay=0.01, # 權重衰減\n",
" save_strategy=\"epoch\", # 每個 epoch 結束後儲存檢查點\n",
" report_to='none',\n",
" )\n",
"\n",
" trainer = Trainer(\n",
" model=model,\n",
" args=training_args,\n",
" train_dataset=train_dataset,\n",
" eval_dataset=eval_dataset,\n",
" tokenizer=tokenizer,\n",
" )\n",
"\n",
" print(\"開始訓練模型...\")\n",
" trainer.train()\n",
" print(\"模型訓練完成!\")\n",
" from tqdm import tqdm\n",
" model.eval()\n",
" total,corr = 0,0\n",
" for i in tqdm(range(len(eval_dataset))):\n",
" inputs = tokenizer(eval_dataset[i]['text'], padding=True, truncation=True, return_tensors=\"pt\").to('cuda')\n",
" with torch.no_grad():\n",
" outputs = model(**inputs)\n",
" logits = outputs.logits\n",
" predictions = torch.argmax(logits, dim=-1)\n",
" res = eval_dataset[i]['label']==predictions.cpu().numpy()[0]\n",
" if not res:\n",
" if predictions.cpu().numpy()[0] in [num_labels-1,num_labels-2] and eval_dataset[i]['label'] in [num_labels-1,num_labels-2]:continue\n",
" print(eval_dataset[i]['text'],eval_dataset[i]['label'],predictions.cpu().numpy()[0],\"lab\",id2label[eval_dataset[i]['label']],'pred',id2label[predictions.cpu().numpy()[0]])\n",
" total+=1\n",
" corr+=res\n",
" print(corr,total,corr/total)\n"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Some weights of ModernBertForSequenceClassification were not initialized from the model checkpoint at /mnt/jeff/InCar/bert/ModernBERT-base and are newly initialized: ['classifier.bias', 'classifier.weight']\n",
"You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"資料前處理中...\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "25703a5df3454fbcbf9a12aead9dc88e",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Generating train split: 0 examples [00:00, ? examples/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "dbf0848a1d48493b9d4464033d9a5b54",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Map: 0%| | 0/77962 [00:00<?, ? examples/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/tmp/ipykernel_2497573/2548920613.py:38: FutureWarning: `tokenizer` is deprecated and will be removed in version 5.0.0 for `Trainer.__init__`. Use `processing_class` instead.\n",
" trainer = Trainer(\n",
"Detected kernel version 4.18.0, which is below the recommended minimum of 5.5.0; this can cause the process to hang. It is recommended to upgrade the kernel to the minimum version or higher.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"開始訓練模型...\n"
]
},
{
"data": {
"text/html": [
"\n",
" <div>\n",
" \n",
" <progress value='29238' max='29238' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
" [29238/29238 21:47, Epoch 3/3]\n",
" </div>\n",
" <table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: left;\">\n",
" <th>Step</th>\n",
" <th>Training Loss</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <td>500</td>\n",
" <td>3.443300</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1000</td>\n",
" <td>1.308000</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1500</td>\n",
" <td>0.635400</td>\n",
" </tr>\n",
" <tr>\n",
" <td>2000</td>\n",
" <td>0.438400</td>\n",
" </tr>\n",
" <tr>\n",
" <td>2500</td>\n",
" <td>0.325100</td>\n",
" </tr>\n",
" <tr>\n",
" <td>3000</td>\n",
" <td>0.283200</td>\n",
" </tr>\n",
" <tr>\n",
" <td>3500</td>\n",
" <td>0.257200</td>\n",
" </tr>\n",
" <tr>\n",
" <td>4000</td>\n",
" <td>0.229000</td>\n",
" </tr>\n",
" <tr>\n",
" <td>4500</td>\n",
" <td>0.235800</td>\n",
" </tr>\n",
" <tr>\n",
" <td>5000</td>\n",
" <td>0.168500</td>\n",
" </tr>\n",
" <tr>\n",
" <td>5500</td>\n",
" <td>0.204100</td>\n",
" </tr>\n",
" <tr>\n",
" <td>6000</td>\n",
" <td>0.172100</td>\n",
" </tr>\n",
" <tr>\n",
" <td>6500</td>\n",
" <td>0.160800</td>\n",
" </tr>\n",
" <tr>\n",
" <td>7000</td>\n",
" <td>0.163500</td>\n",
" </tr>\n",
" <tr>\n",
" <td>7500</td>\n",
" <td>0.179900</td>\n",
" </tr>\n",
" <tr>\n",
" <td>8000</td>\n",
" <td>0.149900</td>\n",
" </tr>\n",
" <tr>\n",
" <td>8500</td>\n",
" <td>0.170100</td>\n",
" </tr>\n",
" <tr>\n",
" <td>9000</td>\n",
" <td>0.148300</td>\n",
" </tr>\n",
" <tr>\n",
" <td>9500</td>\n",
" <td>0.146900</td>\n",
" </tr>\n",
" <tr>\n",
" <td>10000</td>\n",
" <td>0.129400</td>\n",
" </tr>\n",
" <tr>\n",
" <td>10500</td>\n",
" <td>0.103000</td>\n",
" </tr>\n",
" <tr>\n",
" <td>11000</td>\n",
" <td>0.098400</td>\n",
" </tr>\n",
" <tr>\n",
" <td>11500</td>\n",
" <td>0.117700</td>\n",
" </tr>\n",
" <tr>\n",
" <td>12000</td>\n",
" <td>0.099000</td>\n",
" </tr>\n",
" <tr>\n",
" <td>12500</td>\n",
" <td>0.115500</td>\n",
" </tr>\n",
" <tr>\n",
" <td>13000</td>\n",
" <td>0.123600</td>\n",
" </tr>\n",
" <tr>\n",
" <td>13500</td>\n",
" <td>0.120800</td>\n",
" </tr>\n",
" <tr>\n",
" <td>14000</td>\n",
" <td>0.106900</td>\n",
" </tr>\n",
" <tr>\n",
" <td>14500</td>\n",
" <td>0.098400</td>\n",
" </tr>\n",
" <tr>\n",
" <td>15000</td>\n",
" <td>0.073900</td>\n",
" </tr>\n",
" <tr>\n",
" <td>15500</td>\n",
" <td>0.106000</td>\n",
" </tr>\n",
" <tr>\n",
" <td>16000</td>\n",
" <td>0.095900</td>\n",
" </tr>\n",
" <tr>\n",
" <td>16500</td>\n",
" <td>0.107000</td>\n",
" </tr>\n",
" <tr>\n",
" <td>17000</td>\n",
" <td>0.108800</td>\n",
" </tr>\n",
" <tr>\n",
" <td>17500</td>\n",
" <td>0.108000</td>\n",
" </tr>\n",
" <tr>\n",
" <td>18000</td>\n",
" <td>0.094400</td>\n",
" </tr>\n",
" <tr>\n",
" <td>18500</td>\n",
" <td>0.094300</td>\n",
" </tr>\n",
" <tr>\n",
" <td>19000</td>\n",
" <td>0.086100</td>\n",
" </tr>\n",
" <tr>\n",
" <td>19500</td>\n",
" <td>0.094200</td>\n",
" </tr>\n",
" <tr>\n",
" <td>20000</td>\n",
" <td>0.059700</td>\n",
" </tr>\n",
" <tr>\n",
" <td>20500</td>\n",
" <td>0.061400</td>\n",
" </tr>\n",
" <tr>\n",
" <td>21000</td>\n",
" <td>0.070900</td>\n",
" </tr>\n",
" <tr>\n",
" <td>21500</td>\n",
" <td>0.055600</td>\n",
" </tr>\n",
" <tr>\n",
" <td>22000</td>\n",
" <td>0.049200</td>\n",
" </tr>\n",
" <tr>\n",
" <td>22500</td>\n",
" <td>0.047100</td>\n",
" </tr>\n",
" <tr>\n",
" <td>23000</td>\n",
" <td>0.062100</td>\n",
" </tr>\n",
" <tr>\n",
" <td>23500</td>\n",
" <td>0.058300</td>\n",
" </tr>\n",
" <tr>\n",
" <td>24000</td>\n",
" <td>0.038500</td>\n",
" </tr>\n",
" <tr>\n",
" <td>24500</td>\n",
" <td>0.063800</td>\n",
" </tr>\n",
" <tr>\n",
" <td>25000</td>\n",
" <td>0.052600</td>\n",
" </tr>\n",
" <tr>\n",
" <td>25500</td>\n",
" <td>0.058600</td>\n",
" </tr>\n",
" <tr>\n",
" <td>26000</td>\n",
" <td>0.053900</td>\n",
" </tr>\n",
" <tr>\n",
" <td>26500</td>\n",
" <td>0.050200</td>\n",
" </tr>\n",
" <tr>\n",
" <td>27000</td>\n",
" <td>0.054500</td>\n",
" </tr>\n",
" <tr>\n",
" <td>27500</td>\n",
" <td>0.037400</td>\n",
" </tr>\n",
" <tr>\n",
" <td>28000</td>\n",
" <td>0.046200</td>\n",
" </tr>\n",
" <tr>\n",
" <td>28500</td>\n",
" <td>0.048300</td>\n",
" </tr>\n",
" <tr>\n",
" <td>29000</td>\n",
" <td>0.045000</td>\n",
" </tr>\n",
" </tbody>\n",
"</table><p>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"模型訓練完成!\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 2%|▏ | 148/7797 [00:02<01:52, 68.09it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Please leave the window slightly ajar. 133 138 lab WINDOW_POS%set%10 pred WINDOW_POS%set%50\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 2%|▏ | 179/7797 [00:03<01:49, 69.61it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Please remember the seat located in the last row on the left side. 98 97 lab SEAT_POSITION_MEMORY_SET pred SEAT_POSITION_MEMORY_SAVE\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 3%|▎ | 224/7797 [00:03<01:48, 69.59it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Could you please open the car window just a little bit? 133 120 lab WINDOW_POS%set%10 pred WINDOW_POS%increase\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 4%|▍ | 313/7797 [00:04<01:46, 70.14it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Please open the front row car window to about 70 percent. 136 140 lab WINDOW_POS%set%30 pred WINDOW_POS%set%70\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 10%|█ | 817/7797 [00:12<01:39, 69.81it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Please adjust the height of the right headrest on the third row. 72 73 lab SEAT_HEADREST_HEIGHT_POS%decrease pred SEAT_HEADREST_HEIGHT_POS%increase\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 12%|█▏ | 937/7797 [00:13<01:37, 70.19it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Please adjust the length of the right footrest on the third row. 76 77 lab SEAT_LEGREST_FORE_AFT_POS%decrease pred SEAT_LEGREST_FORE_AFT_POS%increase\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 14%|█▍ | 1089/7797 [00:15<01:34, 70.68it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Please assist me in activating the middle row on the right side. 29 34 lab HVAC_RECIRC_MODE% pred HVAC_SCENARIO_MODE%\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 15%|█▍ | 1161/7797 [00:16<01:33, 70.86it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Please adjust the height of the third-row footrest accordingly. 78 79 lab SEAT_LEGREST_HEIGHT_POS%decrease pred SEAT_LEGREST_HEIGHT_POS%increase\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 17%|█▋ | 1296/7797 [00:18<01:34, 68.55it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Would you mind opening the car window just a little bit? 133 120 lab WINDOW_POS%set%10 pred WINDOW_POS%increase\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 18%|█▊ | 1433/7797 [00:20<01:31, 69.59it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Please activate the heating function for the cushion located in the second row on the left side. 39 40 lab HVAC_SEAT_TEMPERATURE_POWER_ON%false pred HVAC_SEAT_TEMPERATURE_POWER_ON%true\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 20%|██ | 1560/7797 [00:22<01:29, 69.53it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Please adjust the lumbar cushion to ensure proper support and comfort. 80 83 lab SEAT_LUMBAR_FORE_AFT_POS%decrease pred SEAT_LUMBAR_HEIGHT_POS%increase\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 21%|██ | 1604/7797 [00:23<01:30, 68.66it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Please put second row right seating back 101 100 lab SEAT_STOW_MODE%STOW pred SEAT_STOW_MODE%RESTORE\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 21%|██ | 1646/7797 [00:23<01:28, 69.34it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Please open the car window to about 80 percent. 141 130 lab WINDOW_POS%set%80 pred WINDOW_POS%increase%80\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 22%|██▏ | 1708/7797 [00:24<01:27, 69.72it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Please assist me in adjusting the car window to about 70 percent of its maximum opening position. 136 129 lab WINDOW_POS%set%30 pred WINDOW_POS%increase%70\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 24%|██▍ | 1860/7797 [00:27<01:24, 70.02it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Could you please open the car window a bit? 134 120 lab WINDOW_POS%set%100 pred WINDOW_POS%increase\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 24%|██▍ | 1904/7797 [00:27<01:25, 69.24it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Please reduce the height of the first row's window by about 10 percent. 133 110 lab WINDOW_POS%set%10 pred WINDOW_POS%decrease%10\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 25%|██▍ | 1926/7797 [00:27<01:24, 69.52it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Please assist in turning on the automatic air circulation for the third row on the right side. 33 30 lab HVAC_RECIRC_MODE%OFF pred HVAC_RECIRC_MODE%AUTO\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 25%|██▌ | 1954/7797 [00:28<01:25, 68.30it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Please assist me in lowering the right-side window of the second row by approximately 20 percent. 141 135 lab WINDOW_POS%set%80 pred WINDOW_POS%set%20\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 29%|██▉ | 2263/7797 [00:32<01:18, 70.07it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Please ensure the proper operation of the middle row lumbar cushion adjustment mechanism. 81 80 lab SEAT_LUMBAR_FORE_AFT_POS%increase pred SEAT_LUMBAR_FORE_AFT_POS%decrease\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 33%|███▎ | 2567/7797 [00:37<01:15, 69.57it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Could you please lower the window a bit? 134 108 lab WINDOW_POS%set%100 pred WINDOW_POS%decrease\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 36%|███▌ | 2817/7797 [00:40<01:11, 69.90it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Please open the window fully. 132 134 lab WINDOW_POS%set%0 pred WINDOW_POS%set%100\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 49%|████▉ | 3815/7797 [00:55<00:57, 69.48it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Could you please lower the car window a bit? 120 108 lab WINDOW_POS%increase pred WINDOW_POS%decrease\n",
"The wind is a bit weak. 23 24 lab HVAC_FAN_SPEED%decrease pred HVAC_FAN_SPEED%increase\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 57%|█████▋ | 4416/7797 [01:03<00:48, 69.62it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Please open the car window just a little bit. 133 120 lab WINDOW_POS%set%10 pred WINDOW_POS%increase\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 66%|██████▌ | 5122/7797 [01:13<00:38, 69.76it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Please assist me with performing the seatback adjustment process. 67 66 lab SEAT_BACKREST_ANGLE_POS%increase pred SEAT_BACKREST_ANGLE_POS%decrease\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 67%|██████▋ | 5254/7797 [01:15<00:36, 69.70it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Please assist me in adjusting the height of the middle row seat. 75 74 lab SEAT_HEIGHT_POS%increase pred SEAT_HEIGHT_POS%decrease\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 72%|███████▏ | 5608/7797 [01:20<00:31, 69.49it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Could you please lower the window of the car in the front row a little bit? 120 108 lab WINDOW_POS%increase pred WINDOW_POS%decrease\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 75%|███████▌ | 5862/7797 [01:24<00:27, 69.90it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Please assist me in adjusting and finishing the installation of the headrest support in the front row seat. 72 73 lab SEAT_HEADREST_HEIGHT_POS%decrease pred SEAT_HEADREST_HEIGHT_POS%increase\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 79%|███████▉ | 6194/7797 [01:29<00:22, 69.91it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Please adjust the legrest on the left side of the first row to its proper position. 78 79 lab SEAT_LEGREST_HEIGHT_POS%decrease pred SEAT_LEGREST_HEIGHT_POS%increase\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 82%|████████▏ | 6356/7797 [01:31<00:20, 68.65it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Could you please turn on the automatic air circulation for the third row? 33 30 lab HVAC_RECIRC_MODE%OFF pred HVAC_RECIRC_MODE%AUTO\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 83%|████████▎ | 6448/7797 [01:32<00:19, 70.49it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Please arrange the seats promptly. 99 101 lab SEAT_STOW_MODE%FOLD pred SEAT_STOW_MODE%STOW\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 83%|████████▎ | 6487/7797 [01:33<00:18, 69.59it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Please move the first row of seats to the right. 70 99 lab SEAT_FORE_AFT_POS%decrease pred SEAT_STOW_MODE%FOLD\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 88%|████████▊ | 6879/7797 [01:39<00:13, 70.52it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Please assist me in turning on the fresh air mode for the middle row first. 33 31 lab HVAC_RECIRC_MODE%OFF pred HVAC_RECIRC_MODE%EXTERNAL\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 90%|████████▉ | 6999/7797 [01:40<00:11, 69.33it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"The breeze is rather gentle. 23 24 lab HVAC_FAN_SPEED%decrease pred HVAC_FAN_SPEED%increase\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 90%|█████████ | 7038/7797 [01:41<00:10, 70.22it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Please pause the electric charging process for a brief moment. 1 0 lab EV_CHARGE_PORT_OPEN%true pred EV_CHARGE_PORT_OPEN%false\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 93%|█████████▎| 7236/7797 [01:44<00:07, 70.59it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Please adjust the position of the lumbar cushion on the third row to make it more comfortable. 81 80 lab SEAT_LUMBAR_FORE_AFT_POS%increase pred SEAT_LUMBAR_FORE_AFT_POS%decrease\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 93%|█████████▎| 7260/7797 [01:44<00:07, 70.92it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" To adjust the height of the seat cushion in the first-row seats, you need to extend it. 68 69 lab SEAT_CUSHION_SIDE_SUPPORT_POS%decrease pred SEAT_CUSHION_SIDE_SUPPORT_POS%increase\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 95%|█████████▌| 7444/7797 [01:47<00:04, 71.19it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Please act quickly to fix the issue with the roof sunshade. 59 58 lab POWER_SUNSHADE%SUNROOF%true pred POWER_SUNSHADE%SUNROOF%false\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 96%|█████████▌| 7484/7797 [01:47<00:04, 70.87it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Please move the ottoman in the first row to the left. 76 77 lab SEAT_LEGREST_FORE_AFT_POS%decrease pred SEAT_LEGREST_FORE_AFT_POS%increase\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 98%|█████████▊| 7659/7797 [01:50<00:01, 70.19it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Please assist me in closing the window to about 90 percent of its full size. 133 119 lab WINDOW_POS%set%10 pred WINDOW_POS%decrease%90\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 7797/7797 [01:52<00:00, 69.57it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"7722 7762 0.994846688997681\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\n"
]
}
],
"source": [
"train_bert_classifier()\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"['Could you please make sure to adjust the position of the lumbar cushion properly?',\n",
" 'Could you please adjust the height of this lumbar cushion to make it more comfortable?',\n",
" 'Could you kindly adjust the position of the backrest on the second row, specifically the seat located on the right?',\n",
" ]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"('WINDOW_POS%increase', 'HVAC_SEAT_VENTILATION_SET%increase')"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"id2label[57],id2label[49]"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"資料前處理中...\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "b1e23d9dbc5341f4b1e4ce1f4c578b7a",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Generating train split: 0 examples [00:00, ? examples/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "e12e5c4e9403475c89e90dea5bd9a07b",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Map: 0%| | 0/55022 [00:00<?, ? examples/s]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"\n",
"\n",
"num_labels = len(id2label)\n",
"model_name = \"/mnt/jeff/InCar/bert/results_classifier2/checkpoint-20631\"\n",
"id2label = json.load(open(f'{model_name}/config.json'))[\"id2label\"]\n",
"id2label = {int(k):id2label[k] for k in id2label}\n",
"label2id = {v: k for k, v in id2label.items()}\n",
"\n",
"tokenizer = AutoTokenizer.from_pretrained(model_name)\n",
"model = AutoModelForSequenceClassification.from_pretrained(\n",
" model_name,\n",
" num_labels=num_labels,\n",
" id2label=id2label,\n",
" label2id=label2id\n",
").to('cuda')\n",
"def preprocess_function(examples):\n",
" return tokenizer(examples[\"text\"], truncation=True, padding=True)\n",
"model.eval()\n",
"print(\"資料前處理中...\")\n",
"dataset = load_dataset('json', data_files='classifier_data.jsonl')\n",
"tokenized_dataset = dataset.map(preprocess_function, batched=True)\n",
"split_dataset = tokenized_dataset['train'].train_test_split(test_size=0.1)\n",
"train_dataset = split_dataset['train']\n",
"eval_dataset = split_dataset['test']"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Inference"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(210, 150)"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from collections import defaultdict\n",
"funcs = defaultdict(set)\n",
"a = set()\n",
"normal_seat = set([\"SEAT_ROW_1_LEFT\",\"SEAT_ROW_1_RIGHT\",\"SEAT_ROW_2_LEFT\",\"SEAT_ROW_2_RIGHT\",\"SEAT_ROW_3_LEFT\",\n",
"\"SEAT_ROW_3_RIGHT\",\"SEAT_ALL\",\"SEAT_ROW_1\",\"SEAT_ROW_2\",\"SEAT_ROW_3\"])\n",
"for tmp in ctrl:\n",
" for conv in tmp['conversations']:\n",
" if conv['from']=='function_call':\n",
" tmp_js = json.loads(conv['value'])[0]\n",
"\n",
" try:\n",
" if 'areaId' in tmp_js[\"arguments\"] and tmp_js[\"arguments\"]['areaId'] in normal_seat:\n",
" tmp_js[\"arguments\"]['areaId']=\"\"\n",
" if 'areaId' in tmp_js[\"arguments\"]:\n",
" func_type_name = tmp_js[\"arguments\"][\"propertyId\"] if tmp_js[\"arguments\"]['areaId']==\"\" else tmp_js[\"arguments\"][\"propertyId\"]+'%'+tmp_js[\"arguments\"]['areaId']\n",
" if 'value' in tmp_js[\"arguments\"] and str(tmp_js[\"arguments\"]['value']).isdigit():\n",
" tmp_js[\"arguments\"]['value'] = int(tmp_js[\"arguments\"]['value'])\n",
" if 'value' in tmp_js[\"arguments\"] and not str(tmp_js[\"arguments\"]['value']).isdigit():\n",
" funcs[func_type_name+'%'+tmp_js[\"arguments\"]['value']].add(str(tmp_js[\"arguments\"]))\n",
" elif 'operation' in tmp_js[\"arguments\"] and tmp_js[\"arguments\"]['operation'] in ['increase','decrease'] and not tmp_js[\"arguments\"][\"propertyId\"] in ['WINDOW_POS']:\n",
" funcs[func_type_name+'%'+tmp_js[\"arguments\"]['operation']].add(str(tmp_js[\"arguments\"]))\n",
" elif tmp_js[\"arguments\"][\"propertyId\"] in ['POWER_SUNSHADE','WINDOW_POS']:\n",
" func_tmp = func_type_name+\"%\"+tmp_js[\"arguments\"][\"operation\"]\n",
" if 'value' in tmp_js[\"arguments\"]:\n",
" func_tmp+='%'+str(tmp_js[\"arguments\"]['value'])\n",
" funcs[func_tmp].add(str(tmp_js[\"arguments\"]))\n",
" else:\n",
" funcs[func_type_name].add(str(tmp_js[\"arguments\"]))\n",
" except:\n",
" if tmp_js['name']==\"set_seat_mode\":\n",
" funcs[tmp_js['name']+'%'+tmp_js[\"arguments\"][\"value\"]].add(str(tmp_js[\"arguments\"]))\n",
" else:\n",
" tmp_js[\"arguments\"]['query']=\"\"\n",
" funcs[tmp_js['name']].add(json.dumps(tmp_js[\"arguments\"]))\n",
"sum(max(1,len(funcs[k])) for k in funcs),len(funcs)\n"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"cls_map = {}\n",
"from copy import deepcopy\n",
"tmp_funcs = deepcopy(funcs)\n",
"for k in tmp_funcs:\n",
" if len(tmp_funcs[k])>=2:\n",
" tmp_s = []\n",
" for a in tmp_funcs[k]:\n",
" tmp_js = json.loads(a.replace(\"'\",'\"'))\n",
" if 'value' in tmp_js and str(tmp_js['value']).isdigit():\n",
" tmp_js['value'] = str(tmp_js['value'])\n",
" if not 'WINDOW_POS' in k or not 'POWER_SUNSHADE' in k: tmp_js['value'] = \"\"\n",
" tmp_s.append(json.dumps(tmp_js))\n",
" tmp_funcs[k] = set(tmp_s)\n",
"for k in tmp_funcs:\n",
" if len(tmp_funcs[k])==1 or 'WINDOW_POS' in k:\n",
" cls_map[k] = json.dumps(json.loads(list(tmp_funcs[k])[0].replace(\"'\",'\"')))\n",
" else:\n",
" print(k, len(tmp_funcs[k]),tmp_funcs[k])"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"json.dump(cls_map,open('response_template.json','w'),ensure_ascii=False,indent=2)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"HVAC_FAN_SPEED\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/tmp/ipykernel_1860429/3952825593.py:155: UserWarning: Implicit dimension choice for softmax has been deprecated. Change the call to include dim=X as an argument.\n",
" confidence = max(torch.nn.functional.softmax(logits[0]))\n"
]
},
{
"data": {
"text/plain": [
"'[{\"name\": \"control_car_properties\", \"arguments\": {\"propertyId\": \"HVAC_FAN_SPEED\", \"areaId\": \"SEAT_ALL\", \"operation\": \"set\", \"value\": \"1\"}}]'"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# import re\n",
"# import json\n",
"# import cn2an\n",
"\n",
"# cls_map = json.load(open('response_template.json'))\n",
"\n",
"# switch_keywords = ['開啟', '開', '打開','啟動','啓動', '關閉', '關', '關掉','停止','停']\n",
"# level_keywords = ['最大','最熱','最高','最低', '最小','最冷']\n",
"\n",
"# area2NL = {\n",
"# \"SEAT_ROW_1_LEFT\": [\"主駕\", \"駕駛座\", \"主駕駛座\", \"第1排左邊\", \"第1排左座\", \"第1排左側\"],\n",
"# \"SEAT_ROW_1_RIGHT\": [\"副駕\", \"副駕駛座\", \"第1排右座\", \"第1排右邊\", \"第1排右側\"],\n",
"# \"SEAT_ROW_2_LEFT\": [\"第2排左側\", \"第2排左座\", \"中間這排左邊\", \"第2排左邊\"],\n",
"# \"SEAT_ROW_2_RIGHT\": [\"第2排右側\", \"第2排右座\", \"中間這排右邊\", \"第2排右邊\"],\n",
"# \"SEAT_ROW_3_LEFT\": [\"第3排左側\", \"第3排左座\", \"最後面這排左邊\", \"最後排左邊\", \"第3排左邊\"],\n",
"# \"SEAT_ROW_3_RIGHT\": [\"第3排右側\", \"第3排右座\", \"最後面這排右邊\", \"最後排右邊\", \"第3排右邊\"],\n",
"# \"SEAT_ALL\": [\"全車\", \"整台車\", \"整部車\"],\n",
"# \"SEAT_ROW_1\": [\"第1排\", \"最前面那排\"],\n",
"# \"SEAT_ROW_2\": [\"第2排\", \"中間那排\"],\n",
"# \"SEAT_ROW_3\": [\"第3排\", \"最後面那排\"],\n",
"# \"SUNROOF\": ['頂棚'],\n",
"# \"SLIDING_DOOR_LEFT\": ['左邊', '左側', '左'],\n",
"# \"SLIDING_DOOR_RIGHT\": ['右邊', '右側', '右'],\n",
"# 'FRONT_WINDSHIELD':['前除霜'],\n",
"# 'REAR_WINDSHIELD':['後除霜'],\n",
"# }\n",
"# NL2area = {nl:k for k in area2NL for nl in area2NL[k]}\n",
"# maxmin_val_map = {\n",
"# 'HVAC_SEAT_VENTILATION_SET':{'max':'3','min':'1'},\n",
"# 'HVAC_SEAT_TEMPERATURE_SET':{'max':'4','min':'1'},\n",
"# 'HVAC_FAN_SPEED':{'max':'8','min':'1'},\n",
"# 'HVAC_TEMPERATURE_SET':{'max':'32','min':'17'},\n",
"# }\n",
"# uncommon_area_NL = set(['頂棚','左邊', '左側', '左','右邊', '右側', '右','前除霜','後除霜'])\n",
"# st_open = set(['開啟', '開', '打開','啟動','啓動'])\n",
"# st_close = set(['關閉', '關', '關掉','停止','停'])\n",
"# default_value = {\n",
"# 'HVAC_TEMPERATURE_SET':'26'\n",
"# }\n",
"\n",
"# def extract_numbers_from_string(text : str):\n",
"# exclude_pattern = r'第\\s*\\d+\\s*排|\\d+\\s*排|1\\s*下|快\\s*1\\s*點|1\\s*團|1\\s*口\\s*氣|1\\s*直'\n",
"# excluded_matches = re.findall(exclude_pattern, text)\n",
"# cleaned_text = text\n",
"# for match in excluded_matches:\n",
"# cleaned_text = cleaned_text.replace(match, '', 1)\n",
"# numbers = re.findall(r'\\d+', cleaned_text)\n",
"# return numbers\n",
"# def get_keywords(text : str):\n",
"\n",
"# tokens = [c for c in text]\n",
" \n",
"# tags = [\"O\"] * len(tokens)\n",
"# keywords = {\"switch\":[],'level':[],'num':[],'area_id':[]}\n",
"# for keyword in switch_keywords:\n",
"# for match in re.finditer(re.escape(keyword), text):\n",
"# start, end = match.span()\n",
"# keywords[\"switch\"].append(text[start:end])\n",
" \n",
"# for keyword in level_keywords:\n",
"# for match in re.finditer(re.escape(keyword), text):\n",
"# start, end = match.span()\n",
"# keywords['level'].append(text[start:end])\n",
" \n",
"# keywords['num'] = extract_numbers_from_string(text)\n",
"\n",
"# for keyword in NL2area.keys():\n",
"# for match in re.finditer(re.escape(keyword), text):\n",
"# start, end = match.span()\n",
"# keywords['area_id'].append(text[start:end])\n",
"# if '副駕駛座' in keywords['area_id'] and not ('前除霜' in keywords['area_id'] or '後除霜' in keywords['area_id']): \n",
"# keywords['area_id']=['副駕駛座']\n",
"# return keywords\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"# def postprocess(query : str,pred_class : str):\n",
"# ori_func_name = pred_class.split('%')[0]\n",
"# func_tmp = cls_map[pred_class]\n",
"# ori_query = query\n",
"# query = cn2an.transform(query)\n",
"# keywords = get_keywords(query)\n",
"# func_tmp = json.loads(func_tmp)\n",
"# if len(keywords['area_id'])!=0:\n",
"# if 'SLIDING_DOOR' in pred_class:\n",
"# for lr in area2NL[\"SLIDING_DOOR_LEFT\"]+area2NL[\"SLIDING_DOOR_RIGHT\"]:\n",
"# if lr in keywords['area_id']:\n",
"# func_tmp['areaId'] = NL2area[lr]\n",
"# elif 'HVAC_DEFROSTER' in pred_class:\n",
"# for fb in ['前除霜','後除霜']: \n",
"# if fb in keywords['area_id']: \n",
"# func_tmp['areaId'] = NL2area[fb]\n",
"# elif 'POWER_SUNSHADE' in pred_class:\n",
"# if '頂棚' in keywords['area_id']:\n",
"# func_tmp['areaId'] = NL2area['頂棚']\n",
"# elif any([right in keywords['area_id'] for right in ['右邊', '右側', '右']]):\n",
"# func_tmp['areaId'] = \"SEAT_ROW_2_RIGHT\"\n",
"# elif any([right in keywords['area_id'] for right in ['左邊', '左側', '左']]):\n",
"# func_tmp['areaId'] = \"SEAT_ROW_2_LEFT\"\n",
"# else:\n",
"# if not keywords['area_id'][0] in uncommon_area_NL:\n",
"# func_tmp['areaId'] = NL2area[keywords['area_id'][0]]\n",
"# if len(keywords['num'])!=0 and 'value' in func_tmp and str(keywords['num'][0]).isdigit() and func_tmp['value'] == '':\n",
"# func_tmp['value'] = str(keywords['num'][0])\n",
"# elif len(keywords[\"level\"])!=0 and 'value' in func_tmp and func_tmp['value'] == '' and ori_func_name in maxmin_val_map:\n",
"# if keywords[\"level\"][0] in ['最大','最熱','最高']:\n",
"# func_tmp['value'] = maxmin_val_map[ori_func_name]['max']\n",
"# elif keywords[\"level\"][0] in ['最低', '最小','最冷']:\n",
"# func_tmp['value'] = maxmin_val_map[ori_func_name]['min']\n",
"# elif len(keywords[\"switch\"])!=0 and ori_func_name in ['POWER_SUNSHADE'] and 'value' in func_tmp and func_tmp['value'] == '':\n",
"# for op in keywords[\"switch\"]:\n",
"# if op in st_open and not '開大' in query: func_tmp['value']='100'\n",
"# elif op in st_close and not '關小' in query: func_tmp['value']='0'\n",
"\n",
" \n",
"# if 'value' in func_tmp and func_tmp['value']=='':\n",
"# if 'increase' in pred_class or 'decrease' in pred_class:func_tmp['value']='1'\n",
"# elif ori_func_name == 'HVAC_TEMPERATURE_SET':\n",
"# if '熱' in query: func_tmp['value'] = maxmin_val_map[ori_func_name]['min']\n",
"# elif '冷' in query or '凍' in query: func_tmp['value'] = maxmin_val_map[ori_func_name]['max']\n",
"# elif ori_func_name in default_value:func_tmp['value']=default_value[ori_func_name]\n",
"\n",
"\n",
"# if ori_func_name in ['set_seat_mode']:\n",
"# func_tmp = [{\"name\":ori_func_name,\"arguments\":func_tmp}]\n",
"# elif ori_func_name in ['get_hhtd_info','get_vehicle_info']:\n",
"# func_tmp['query'] = ori_query\n",
"# func_tmp = [{\"name\":ori_func_name,\"arguments\":func_tmp}]\n",
"# else:\n",
"# func_tmp = [{\"name\":\"control_car_properties\",\"arguments\":func_tmp}]\n",
"# return json.dumps(func_tmp, ensure_ascii=False)\n",
"\n",
"# ### Examples\n",
"\n",
"# output1 = postprocess(\"請打開副駕駛座前除霜\",'HVAC_DEFROSTER%true')\n",
"# # outout1 = '[{\"name\": \"control_car_properties\", \"arguments\": {\"propertyId\": \"HVAC_DEFROSTER\", \"areaId\": \"FRONT_WINDSHIELD\", \"operation\": \"set\", \"value\": \"true\"}}]'\n",
"\n",
"# output2 = postprocess(\"冷到一直打噴嚏\",'HVAC_TEMPERATURE_SET')\n",
"# # output2 = '[{\"name\": \"control_car_properties\", \"arguments\": {\"propertyId\": \"HVAC_TEMPERATURE_SET\", \"areaId\": \"\", \"operation\": \"set\", \"value\": \"32\"}}]'\n",
"\n",
"# output3 = postprocess(\"麻煩您將整部車風量調到最小\",'HVAC_FAN_SPEED')\n",
"# # output3 = '[{\"name\": \"control_car_properties\", \"arguments\": {\"propertyId\": \"HVAC_FAN_SPEED\", \"areaId\": \"SEAT_ALL\", \"operation\": \"set\", \"value\": \"1\"}}]'\n",
"\n",
"# # for q in ['風再弱些謝謝','出風別那麼強','溫度有點高','風小一點謝謝','讓陽光多一些','陽光有點刺眼']:\n",
"# # inference(q)\n",
"# dic = {'兩':'2'}\n",
"# def inference(query):\n",
"# for k in dic:query=query.replace(k,dic[k])\n",
"# inputs = tokenizer(query, padding=True, truncation=True, return_tensors=\"pt\").to('cuda')\n",
"# with torch.no_grad():\n",
"# outputs = model(**inputs)\n",
"# logits = outputs.logits\n",
"# confidence = max(torch.nn.functional.softmax(logits[0]))\n",
"# predictions = torch.argmax(logits, dim=-1)\n",
"# pred_class = id2label[predictions.cpu().numpy()[0]]\n",
"# print(pred_class)\n",
"# if pred_class=='others':return {},{},pred_class\n",
"# return postprocess(query,pred_class)\n",
"# inference(\"麻煩您將整部車風量調到最小\")"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"HVAC_POWER_ON%true\n",
"[{'arguments': {'areaId': '', 'operation': 'set', 'propertyId': 'HVAC_POWER_ON', 'value': 'true'}, 'name': 'control_car_properties'}]\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/tmp/ipykernel_244741/687995418.py:36: UserWarning: Implicit dimension choice for softmax has been deprecated. Change the call to include dim=X as an argument.\n",
" confidence = max(torch.nn.functional.softmax(logits[0]))\n",
"[ERROR] keywords_data.json file not found. Please ensure it's in the same directory.\n"
]
}
],
"source": [
"import ctypes\n",
"import json\n",
"\n",
"\n",
"lib_path = './cpp_postprocess/postprocess.so'\n",
"lib = ctypes.CDLL(lib_path)\n",
"\n",
"\n",
"# 設定函式參數和回傳值的資料型別\n",
"# postprocess_c 函式接收兩個 C 字串並回傳一個 C 字串\n",
"lib.postprocess_c.argtypes = [ctypes.c_char_p, ctypes.c_char_p]\n",
"lib.postprocess_c.restype = ctypes.c_char_p\n",
"\n",
"def process_cpp(query, pred_class):\n",
" # 將 Python 字串編碼為 bytes,以符合 C++ 的 char* 參數要求\n",
" query_bytes = query.encode('utf-8')\n",
" pred_class_bytes = pred_class.encode('utf-8')\n",
" \n",
" # 呼叫 C++ 函式\n",
" result_ptr = lib.postprocess_c(query_bytes, pred_class_bytes)\n",
" \n",
" # 將回傳的 C 字串解碼為 Python 字串\n",
" if result_ptr:\n",
" result_str = result_ptr.decode('utf-8')\n",
" # 釋放 C++ 函式動態分配的記憶體\n",
" return result_str\n",
" else:\n",
" return None\n",
"dic = {'兩':'2'}\n",
"def inference_cpp(query):\n",
" for k in dic:query=query.replace(k,dic[k])\n",
" inputs = tokenizer(query, padding=True, truncation=True, return_tensors=\"pt\").to('cuda')\n",
" with torch.no_grad():\n",
" outputs = model(**inputs)\n",
" logits = outputs.logits\n",
" confidence = max(torch.nn.functional.softmax(logits[0]))\n",
" predictions = torch.argmax(logits, dim=-1)\n",
" pred_class = id2label[predictions.cpu().numpy()[0]]\n",
" print(pred_class)\n",
" if pred_class=='others':return {},{},pred_class\n",
" return process_cpp(query,pred_class),pred_class\n",
"# a = json.loads(inference_cpp(\"幫我完成第三排右側椅背往後操作\")[0])\n",
"a = json.loads(inference_cpp(\"Could you please turn on the air conditioner in the last row?\")[0])\n",
"\n",
"# b = json.loads(inference(\"幫我完成第三排右側椅背往後操作\"))\n",
"print(a)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"SEAT_BACKREST_ANGLE_POS%decrease\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/tmp/ipykernel_1860429/3952825593.py:155: UserWarning: Implicit dimension choice for softmax has been deprecated. Change the call to include dim=X as an argument.\n",
" confidence = max(torch.nn.functional.softmax(logits[0]))\n"
]
},
{
"data": {
"text/plain": [
"'[{\"name\": \"control_car_properties\", \"arguments\": {\"propertyId\": \"SEAT_BACKREST_ANGLE_POS\", \"areaId\": \"SEAT_ROW_3_RIGHT\", \"operation\": \"decrease\"}}]'"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
" 0%| | 0/5000 [00:00<?, ?it/s]/tmp/ipykernel_1796089/100130921.py:39: UserWarning: Implicit dimension choice for softmax has been deprecated. Change the call to include dim=X as an argument.\n",
" confidence = max(torch.nn.functional.softmax(logits[0]))\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"請將第二排左側窗戶開一點\n",
"[{'arguments': {'areaId': '', 'operation': 'increase', 'propertyId': 'WINDOW_POS'}, 'name': 'control_car_properties'}]\n",
"[{'name': 'control_car_properties', 'arguments': {'propertyId': 'WINDOW_POS', 'areaId': 'SEAT_ROW_2_LEFT', 'operation': 'increase'}}]\n",
"('WINDOW_POS%increase',)\n",
"------------\n",
"幫我完成第三排右側椅背往後操作\n",
"[{'arguments': {'areaId': '', 'operation': 'decrease', 'propertyId': 'SEAT_BACKREST_ANGLE_POS'}, 'name': 'control_car_properties'}]\n",
"[{'name': 'control_car_properties', 'arguments': {'propertyId': 'SEAT_BACKREST_ANGLE_POS', 'areaId': 'SEAT_ROW_3_RIGHT', 'operation': 'decrease'}}]\n",
"('SEAT_BACKREST_ANGLE_POS%decrease',)\n",
"------------\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 0%| | 1/5000 [00:00<38:05, 2.19it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"關第二排左側遮陽簾\n",
"[{'arguments': {'areaId': '', 'operation': 'set', 'propertyId': 'POWER_SUNSHADE', 'value': '0'}, 'name': 'control_car_properties'}]\n",
"[{'name': 'control_car_properties', 'arguments': {'propertyId': 'POWER_SUNSHADE', 'areaId': 'SEAT_ROW_2_LEFT', 'operation': 'set', 'value': '0'}}]\n",
"('POWER_SUNSHADE',)\n",
"------------\n",
"立刻關掉第二排右側遮陽簾\n",
"[{'arguments': {'areaId': '', 'operation': 'set', 'propertyId': 'POWER_SUNSHADE', 'value': '0'}, 'name': 'control_car_properties'}]\n",
"[{'name': 'control_car_properties', 'arguments': {'propertyId': 'POWER_SUNSHADE', 'areaId': 'SEAT_ROW_2_RIGHT', 'operation': 'set', 'value': '0'}}]\n",
"('POWER_SUNSHADE',)\n",
"------------\n",
"嘿座椅通風降低五檔\n",
"[{'arguments': {'areaId': '', 'operation': 'decrease', 'propertyId': 'HVAC_SEAT_VENTILATION_SET', 'value': '0'}, 'name': 'control_car_properties'}]\n",
"[{'name': 'control_car_properties', 'arguments': {'propertyId': 'HVAC_SEAT_VENTILATION_SET', 'areaId': '', 'operation': 'decrease', 'value': '5'}}]\n",
"('HVAC_SEAT_VENTILATION_SET%decrease',)\n",
"------------\n",
"幫我完成駕駛座Ottoman腿托升高操作\n",
"[{'arguments': {'areaId': '', 'operation': 'increase', 'propertyId': 'SEAT_LEGREST_HEIGHT_POS'}, 'name': 'control_car_properties'}]\n",
"[{'name': 'control_car_properties', 'arguments': {'propertyId': 'SEAT_LEGREST_HEIGHT_POS', 'areaId': 'SEAT_ROW_1_LEFT', 'operation': 'increase'}}]\n",
"('SEAT_LEGREST_HEIGHT_POS%increase',)\n",
"------------\n",
"設定第二排左側座位按摩部位為背部\n",
"[{'arguments': {'areaId': '', 'operation': 'set', 'propertyId': 'SEAT_MASSAGE_REGION', 'value': 'BACK'}, 'name': 'control_car_properties'}]\n",
"[{'name': 'control_car_properties', 'arguments': {'propertyId': 'SEAT_MASSAGE_REGION', 'areaId': 'SEAT_ROW_2_LEFT', 'operation': 'set', 'value': 'BACK'}}]\n",
"('SEAT_MASSAGE_REGION%BACK',)\n",
"------------\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 0%| | 3/5000 [00:01<29:35, 2.81it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"直接把風量調小一點\n",
"[{'arguments': {'areaId': '', 'operation': 'decrease', 'propertyId': 'HVAC_FAN_SPEED', 'value': '0'}, 'name': 'control_car_properties'}]\n",
"[{'name': 'control_car_properties', 'arguments': {'propertyId': 'HVAC_FAN_SPEED', 'areaId': '', 'operation': 'decrease', 'value': '1'}}]\n",
"('HVAC_FAN_SPEED%decrease',)\n",
"------------\n",
"麻煩設置第三排腿部支撐變低到位\n",
"[{'arguments': {'areaId': '', 'operation': 'decrease', 'propertyId': 'SEAT_CUSHION_SIDE_SUPPORT_POS'}, 'name': 'control_car_properties'}]\n",
"[{'name': 'control_car_properties', 'arguments': {'propertyId': 'SEAT_CUSHION_SIDE_SUPPORT_POS', 'areaId': 'SEAT_ROW_3', 'operation': 'decrease'}}]\n",
"('SEAT_CUSHION_SIDE_SUPPORT_POS%decrease',)\n",
"------------\n",
"請讓第三排左座車窗維持關一半\n",
"[{'arguments': {'areaId': '', 'operation': 'set', 'propertyId': 'WINDOW_POS', 'value': '50'}, 'name': 'control_car_properties'}]\n",
"[{'name': 'control_car_properties', 'arguments': {'propertyId': 'WINDOW_POS', 'areaId': 'SEAT_ROW_3_LEFT', 'operation': 'set', 'value': '50'}}]\n",
"('WINDOW_POS%50',)\n",
"------------\n",
"快將溫度調弱3度\n",
"[{'arguments': {'areaId': '', 'operation': 'decrease', 'propertyId': 'HVAC_TEMPERATURE_SET', 'value': '0'}, 'name': 'control_car_properties'}]\n",
"[{'name': 'control_car_properties', 'arguments': {'propertyId': 'HVAC_TEMPERATURE_SET', 'areaId': '', 'operation': 'decrease', 'value': '3'}}]\n",
"('HVAC_TEMPERATURE_SET%decrease',)\n",
"------------\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 0%| | 4/5000 [00:01<42:02, 1.98it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"先幫我開啟最前面那排AUTO\n",
"[{'arguments': {'areaId': '', 'operation': 'set', 'propertyId': 'HVAC_AUTO_ON', 'value': 'true'}, 'name': 'control_car_properties'}]\n",
"[{'name': 'control_car_properties', 'arguments': {'propertyId': 'HVAC_AUTO_ON', 'areaId': 'SEAT_ROW_1', 'operation': 'set', 'value': 'true'}}]\n",
"('HVAC_AUTO_ON%true',)\n",
"------------\n",
"第三排半關窗戶\n",
"[{'arguments': {'areaId': '', 'operation': 'set', 'propertyId': 'WINDOW_POS', 'value': '50'}, 'name': 'control_car_properties'}]\n",
"[{'name': 'control_car_properties', 'arguments': {'propertyId': 'WINDOW_POS', 'areaId': 'SEAT_ROW_3', 'operation': 'set', 'value': '50'}}]\n",
"('WINDOW_POS%50',)\n",
"------------\n",
"快整台車風量調小兩檔\n",
"[{'arguments': {'areaId': '', 'operation': 'decrease', 'propertyId': 'HVAC_FAN_SPEED', 'value': '0'}, 'name': 'control_car_properties'}]\n",
"[{'name': 'control_car_properties', 'arguments': {'propertyId': 'HVAC_FAN_SPEED', 'areaId': 'SEAT_ALL', 'operation': 'decrease', 'value': '2'}}]\n",
"('HVAC_FAN_SPEED%decrease',)\n",
"------------\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 0%| | 5/5000 [00:02<34:27, 2.42it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"請操作中間那排大腿支撐調高\n",
"[{'arguments': {'areaId': '', 'operation': 'increase', 'propertyId': 'SEAT_CUSHION_SIDE_SUPPORT_POS'}, 'name': 'control_car_properties'}]\n",
"[{'name': 'control_car_properties', 'arguments': {'propertyId': 'SEAT_CUSHION_SIDE_SUPPORT_POS', 'areaId': 'SEAT_ROW_2', 'operation': 'increase'}}]\n",
"('SEAT_CUSHION_SIDE_SUPPORT_POS%increase',)\n",
"------------\n",
"第二排左座窗戶關閉百分之70\n",
"[{'arguments': {'areaId': '', 'operation': 'set', 'propertyId': 'WINDOW_POS', 'value': '30'}, 'name': 'control_car_properties'}]\n",
"[{'name': 'control_car_properties', 'arguments': {'propertyId': 'WINDOW_POS', 'areaId': 'SEAT_ROW_2_LEFT', 'operation': 'set', 'value': '30'}}]\n",
"('WINDOW_POS%30',)\n",
"------------\n",
"麻煩完成座椅加熱轉到6檔設定\n",
"[{'arguments': {'areaId': '', 'operation': 'set', 'propertyId': 'HVAC_SEAT_TEMPERATURE_SET', 'value': '0'}, 'name': 'control_car_properties'}]\n",
"[{'name': 'control_car_properties', 'arguments': {'propertyId': 'HVAC_SEAT_TEMPERATURE_SET', 'areaId': '', 'operation': 'set', 'value': '6'}}]\n",
"('HVAC_SEAT_TEMPERATURE_SET',)\n",
"------------\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 0%| | 6/5000 [00:02<28:33, 2.91it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"第一排右側窗戶直接打開\n",
"[{'arguments': {'areaId': '', 'operation': 'set', 'propertyId': 'WINDOW_POS', 'value': '100'}, 'name': 'control_car_properties'}]\n",
"[{'name': 'control_car_properties', 'arguments': {'propertyId': 'WINDOW_POS', 'areaId': 'SEAT_ROW_1_RIGHT', 'operation': 'set', 'value': '100'}}]\n",
"('WINDOW_POS%100',)\n",
"------------\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 0%| | 8/5000 [00:03<26:03, 3.19it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"第三排溫度向下8度啦\n",
"[{'arguments': {'areaId': '', 'operation': 'decrease', 'propertyId': 'HVAC_TEMPERATURE_SET', 'value': '3'}, 'name': 'control_car_properties'}]\n",
"[{'name': 'control_car_properties', 'arguments': {'propertyId': 'HVAC_TEMPERATURE_SET', 'areaId': 'SEAT_ROW_3', 'operation': 'decrease', 'value': '8'}}]\n",
"('HVAC_TEMPERATURE_SET%decrease',)\n",
"------------\n",
"麻煩幫我停止第三排右邊外循環\n",
"[{'arguments': {'areaId': '', 'operation': 'set', 'propertyId': 'HVAC_RECIRC_MODE', 'value': 'OFF'}, 'name': 'control_car_properties'}]\n",
"[{'name': 'control_car_properties', 'arguments': {'propertyId': 'HVAC_RECIRC_MODE', 'areaId': 'SEAT_ROW_3_RIGHT', 'operation': 'set', 'value': 'OFF'}}]\n",
"('HVAC_RECIRC_MODE%OFF',)\n",
"------------\n",
"幫我把第二排右側車窗關上留條縫\n",
"[{'arguments': {'areaId': '', 'operation': 'set', 'propertyId': 'WINDOW_POS', 'value': '10'}, 'name': 'control_car_properties'}]\n",
"[{'name': 'control_car_properties', 'arguments': {'propertyId': 'WINDOW_POS', 'areaId': 'SEAT_ROW_2_RIGHT', 'operation': 'set', 'value': '10'}}]\n",
"('WINDOW_POS%10',)\n",
"------------\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 0%| | 9/5000 [00:03<35:00, 2.38it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"請讓主駕駛座椅墊退出辦公模式\n",
"[{'arguments': {'areaId': '', 'operation': 'set', 'value': 'OFF'}, 'name': 'set_seat_mode'}]\n",
"[{'name': 'set_seat_mode', 'arguments': {'areaId': 'SEAT_ROW_1_LEFT', 'operation': 'set', 'value': 'OFF'}}]\n",
"('set_seat_mode%OFF',)\n",
"------------\n",
"副駕先自由關閉\n",
"[{'arguments': {'areaId': '', 'operation': 'set', 'propertyId': 'HVAC_FAN_OUTPUT_MODE', 'value': 'OFF'}, 'name': 'control_car_properties'}]\n",
"[{'name': 'control_car_properties', 'arguments': {'propertyId': 'HVAC_FAN_OUTPUT_MODE', 'areaId': 'SEAT_ROW_1_RIGHT', 'operation': 'set', 'value': 'OFF'}}]\n",
"('HVAC_FAN_OUTPUT_MODE%OFF',)\n",
"------------\n",
"請關左邊電滑門\n",
"[{'arguments': {'areaId': '', 'operation': 'set', 'propertyId': 'SLIDING_DOOR_ON', 'value': 'false'}, 'name': 'control_car_properties'}]\n",
"[{'name': 'control_car_properties', 'arguments': {'propertyId': 'SLIDING_DOOR_ON', 'areaId': 'SLIDING_DOOR_LEFT', 'operation': 'set', 'value': 'false'}}]\n",
"('SLIDING_DOOR_ON%false',)\n",
"------------\n",
"快點開第二排右側遮陽簾\n",
"[{'arguments': {'areaId': '', 'operation': 'set', 'propertyId': 'POWER_SUNSHADE', 'value': '0'}, 'name': 'control_car_properties'}]\n",
"[{'name': 'control_car_properties', 'arguments': {'propertyId': 'POWER_SUNSHADE', 'areaId': 'SEAT_ROW_2_RIGHT', 'operation': 'set', 'value': '100'}}]\n",
"('POWER_SUNSHADE',)\n",
"------------\n",
"幫我控制完成中間那排椅子加熱加高一點\n",
"[{'arguments': {'areaId': '', 'operation': 'increase', 'propertyId': 'HVAC_SEAT_TEMPERATURE_SET', 'value': '0'}, 'name': 'control_car_properties'}]\n",
"[{'name': 'control_car_properties', 'arguments': {'propertyId': 'HVAC_SEAT_TEMPERATURE_SET', 'areaId': 'SEAT_ROW_2', 'operation': 'increase', 'value': '1'}}]\n",
"('HVAC_SEAT_TEMPERATURE_SET%increase',)\n",
"------------\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 0%| | 11/5000 [00:04<39:09, 2.12it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"讓中間那排座椅復原\n",
"[{'arguments': {'areaId': '', 'operation': 'set', 'propertyId': 'SEAT_STOW_MODE', 'value': 'RESTORE'}, 'name': 'control_car_properties'}]\n",
"[{'name': 'control_car_properties', 'arguments': {'propertyId': 'SEAT_STOW_MODE', 'areaId': 'SEAT_ROW_2', 'operation': 'set', 'value': 'RESTORE'}}]\n",
"('SEAT_STOW_MODE%RESTORE',)\n",
"------------\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 0%| | 12/5000 [00:05<33:57, 2.45it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"可以幫我把整部車座位設定成零重力模式\n",
"[{'arguments': {'areaId': '', 'operation': 'set', 'value': 'ZERO_GRAVITY'}, 'name': 'set_seat_mode'}]\n",
"[{'name': 'set_seat_mode', 'arguments': {'areaId': 'SEAT_ALL', 'operation': 'set', 'value': 'ZERO_GRAVITY'}}]\n",
"('set_seat_mode%ZERO_GRAVITY',)\n",
"------------\n",
"麻煩把第一排椅墊往調後稍稍後移\n",
"[{'arguments': {'areaId': '', 'operation': 'decrease', 'propertyId': 'SEAT_FORE_AFT_POS'}, 'name': 'control_car_properties'}]\n",
"[{'name': 'control_car_properties', 'arguments': {'propertyId': 'SEAT_FORE_AFT_POS', 'areaId': 'SEAT_ROW_1', 'operation': 'decrease'}}]\n",
"('SEAT_FORE_AFT_POS%decrease',)\n",
"------------\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 0%| | 14/5000 [00:05<31:50, 2.61it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"麻煩將打開第一排座椅加熱\n",
"[{'arguments': {'areaId': '', 'operation': 'set', 'propertyId': 'HVAC_SEAT_TEMPERATURE_POWER_ON', 'value': 'true'}, 'name': 'control_car_properties'}]\n",
"[{'name': 'control_car_properties', 'arguments': {'propertyId': 'HVAC_SEAT_TEMPERATURE_POWER_ON', 'areaId': 'SEAT_ROW_1', 'operation': 'set', 'value': 'true'}}]\n",
"('HVAC_SEAT_TEMPERATURE_POWER_ON%true',)\n",
"------------\n",
"第二排左座椅子按摩強度設定,請轉到中等檔\n",
"[{'arguments': {'areaId': '', 'operation': 'set', 'propertyId': 'SEAT_MASSAGE_INTENSITY', 'value': 'MEDIUM'}, 'name': 'control_car_properties'}]\n",
"[{'name': 'control_car_properties', 'arguments': {'propertyId': 'SEAT_MASSAGE_INTENSITY', 'areaId': 'SEAT_ROW_2_LEFT', 'operation': 'set', 'value': 'MEDIUM'}}]\n",
"('SEAT_MASSAGE_INTENSITY%MEDIUM',)\n",
"------------\n",
"主駕駛座出風掃風馬上關閉\n",
"[{'arguments': {'areaId': '', 'operation': 'set', 'propertyId': 'HVAC_FAN_OUTPUT_MODE', 'value': 'OFF'}, 'name': 'control_car_properties'}]\n",
"[{'name': 'control_car_properties', 'arguments': {'propertyId': 'HVAC_FAN_OUTPUT_MODE', 'areaId': 'SEAT_ROW_1_LEFT', 'operation': 'set', 'value': 'OFF'}}]\n",
"('HVAC_FAN_OUTPUT_MODE%OFF',)\n",
"------------\n",
"先幫我啓動第三排維持模式\n",
"[{'arguments': {'areaId': '', 'operation': 'set', 'propertyId': 'HVAC_SCENARIO_MODE', 'value': 'MAINTAIN'}, 'name': 'control_car_properties'}]\n",
"[{'name': 'control_car_properties', 'arguments': {'propertyId': 'HVAC_SCENARIO_MODE', 'areaId': 'SEAT_ROW_3', 'operation': 'set', 'value': 'MAINTAIN'}}]\n",
"('HVAC_SCENARIO_MODE%MAINTAIN',)\n",
"------------\n",
"頂棚遮陽簾快開\n",
"[{'arguments': {'areaId': '', 'operation': 'set', 'propertyId': 'POWER_SUNSHADE', 'value': '0'}, 'name': 'control_car_properties'}]\n",
"[{'name': 'control_car_properties', 'arguments': {'propertyId': 'POWER_SUNSHADE', 'areaId': 'SUNROOF', 'operation': 'set', 'value': '100'}}]\n",
"('POWER_SUNSHADE',)\n",
"------------\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 0%| | 15/5000 [00:06<35:11, 2.36it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"請幫忙副駕座位加熱調弱一點\n",
"[{'arguments': {'areaId': '', 'operation': 'decrease', 'propertyId': 'HVAC_SEAT_TEMPERATURE_SET', 'value': '0'}, 'name': 'control_car_properties'}]\n",
"[{'name': 'control_car_properties', 'arguments': {'propertyId': 'HVAC_SEAT_TEMPERATURE_SET', 'areaId': 'SEAT_ROW_1_RIGHT', 'operation': 'decrease', 'value': '1'}}]\n",
"('HVAC_SEAT_TEMPERATURE_SET%decrease',)\n",
"------------\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 0%| | 17/5000 [00:07<33:54, 2.45it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"麻煩將第三排右邊座椅加熱切到最小\n",
"[{'arguments': {'areaId': '', 'operation': 'set', 'propertyId': 'HVAC_SEAT_TEMPERATURE_SET', 'value': '0'}, 'name': 'control_car_properties'}]\n",
"[{'name': 'control_car_properties', 'arguments': {'propertyId': 'HVAC_SEAT_TEMPERATURE_SET', 'areaId': 'SEAT_ROW_3_RIGHT', 'operation': 'set', 'value': '1'}}]\n",
"('HVAC_SEAT_TEMPERATURE_SET',)\n",
"------------\n",
"幫忙關閉第三排左邊維持模式\n",
"[{'arguments': {'areaId': '', 'operation': 'set', 'propertyId': 'HVAC_SCENARIO_MODE', 'value': 'OFF'}, 'name': 'control_car_properties'}]\n",
"[{'name': 'control_car_properties', 'arguments': {'propertyId': 'HVAC_SCENARIO_MODE', 'areaId': 'SEAT_ROW_3_LEFT', 'operation': 'set', 'value': 'OFF'}}]\n",
"('HVAC_SCENARIO_MODE%OFF',)\n",
"------------\n",
"第二排左座打開MAX\n",
"[{'arguments': {'areaId': '', 'operation': 'set', 'propertyId': 'HVAC_MAX_AC_ON', 'value': 'true'}, 'name': 'control_car_properties'}]\n",
"[{'name': 'control_car_properties', 'arguments': {'propertyId': 'HVAC_MAX_AC_ON', 'areaId': 'SEAT_ROW_2_LEFT', 'operation': 'set', 'value': 'true'}}]\n",
"('HVAC_MAX_AC_ON%true',)\n",
"------------\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 0%| | 18/5000 [00:08<44:03, 1.88it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"設定最後排右邊座椅通風設為四檔\n",
"[{'arguments': {'areaId': '', 'operation': 'set', 'propertyId': 'HVAC_SEAT_VENTILATION_SET', 'value': '0'}, 'name': 'control_car_properties'}]\n",
"[{'name': 'control_car_properties', 'arguments': {'propertyId': 'HVAC_SEAT_VENTILATION_SET', 'areaId': 'SEAT_ROW_3_RIGHT', 'operation': 'set', 'value': '4'}}]\n",
"('HVAC_SEAT_VENTILATION_SET',)\n",
"------------\n",
"先風量調大一點\n",
"[{'arguments': {'areaId': '', 'operation': 'increase', 'propertyId': 'HVAC_FAN_SPEED', 'value': '0'}, 'name': 'control_car_properties'}]\n",
"[{'name': 'control_car_properties', 'arguments': {'propertyId': 'HVAC_FAN_SPEED', 'areaId': '', 'operation': 'increase', 'value': '1'}}]\n",
"('HVAC_FAN_SPEED%increase',)\n",
"------------\n",
"立刻關閉中間那排自動循環\n",
"[{'arguments': {'areaId': '', 'operation': 'set', 'propertyId': 'HVAC_RECIRC_MODE', 'value': 'OFF'}, 'name': 'control_car_properties'}]\n",
"[{'name': 'control_car_properties', 'arguments': {'propertyId': 'HVAC_RECIRC_MODE', 'areaId': 'SEAT_ROW_2', 'operation': 'set', 'value': 'OFF'}}]\n",
"('HVAC_RECIRC_MODE%OFF',)\n",
"------------\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 0%| | 18/5000 [00:08<39:28, 2.10it/s]\n"
]
},
{
"ename": "KeyboardInterrupt",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[12], line 6\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m idx,conv \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28menumerate\u001b[39m(data[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mconversations\u001b[39m\u001b[38;5;124m'\u001b[39m]):\n\u001b[1;32m 5\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m conv[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mfrom\u001b[39m\u001b[38;5;124m'\u001b[39m]\u001b[38;5;241m==\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mhuman\u001b[39m\u001b[38;5;124m'\u001b[39m \u001b[38;5;129;01mand\u001b[39;00m data[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mconversations\u001b[39m\u001b[38;5;124m'\u001b[39m][idx\u001b[38;5;241m+\u001b[39m\u001b[38;5;241m1\u001b[39m][\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mfrom\u001b[39m\u001b[38;5;124m'\u001b[39m]\u001b[38;5;241m==\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mfunction_call\u001b[39m\u001b[38;5;124m'\u001b[39m:\n\u001b[0;32m----> 6\u001b[0m model_out \u001b[38;5;241m=\u001b[39m inference_cpp(conv[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mvalue\u001b[39m\u001b[38;5;124m'\u001b[39m])\n\u001b[1;32m 7\u001b[0m a \u001b[38;5;241m=\u001b[39m json\u001b[38;5;241m.\u001b[39mloads(model_out[\u001b[38;5;241m0\u001b[39m]) \u001b[38;5;28;01mif\u001b[39;00m model_out[\u001b[38;5;241m0\u001b[39m]\u001b[38;5;241m!=\u001b[39m{} \u001b[38;5;28;01melse\u001b[39;00m {}\n\u001b[1;32m 8\u001b[0m b \u001b[38;5;241m=\u001b[39m json\u001b[38;5;241m.\u001b[39mloads(data[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mconversations\u001b[39m\u001b[38;5;124m'\u001b[39m][idx\u001b[38;5;241m+\u001b[39m\u001b[38;5;241m1\u001b[39m][\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mvalue\u001b[39m\u001b[38;5;124m'\u001b[39m]\u001b[38;5;241m.\u001b[39mreplace(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m兩\u001b[39m\u001b[38;5;124m'\u001b[39m,\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m2\u001b[39m\u001b[38;5;124m'\u001b[39m))\n",
"Cell \u001b[0;32mIn[11], line 39\u001b[0m, in \u001b[0;36minference_cpp\u001b[0;34m(query)\u001b[0m\n\u001b[1;32m 37\u001b[0m outputs \u001b[38;5;241m=\u001b[39m model(\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39minputs)\n\u001b[1;32m 38\u001b[0m logits \u001b[38;5;241m=\u001b[39m outputs\u001b[38;5;241m.\u001b[39mlogits\n\u001b[0;32m---> 39\u001b[0m confidence \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mmax\u001b[39m(torch\u001b[38;5;241m.\u001b[39mnn\u001b[38;5;241m.\u001b[39mfunctional\u001b[38;5;241m.\u001b[39msoftmax(logits[\u001b[38;5;241m0\u001b[39m]))\n\u001b[1;32m 40\u001b[0m predictions \u001b[38;5;241m=\u001b[39m torch\u001b[38;5;241m.\u001b[39margmax(logits, dim\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m)\n\u001b[1;32m 41\u001b[0m pred_class \u001b[38;5;241m=\u001b[39m id2label[predictions\u001b[38;5;241m.\u001b[39mcpu()\u001b[38;5;241m.\u001b[39mnumpy()[\u001b[38;5;241m0\u001b[39m]]\n",
"\u001b[0;31mKeyboardInterrupt\u001b[0m: "
]
}
],
"source": [
"from tqdm import tqdm\n",
"wrong = []\n",
"for data in tqdm(ctrl):\n",
" for idx,conv in enumerate(data['conversations']):\n",
" if conv['from']=='human' and data['conversations'][idx+1]['from']=='function_call':\n",
" model_out = inference_cpp(conv['value'])\n",
" a = json.loads(model_out[0]) if model_out[0]!={} else {}\n",
" b = json.loads(data['conversations'][idx+1]['value'].replace('兩','2'))\n",
" if 'value' in b[0]['arguments']:b[0]['arguments']['value'] = str(b[0]['arguments']['value'])\n",
" if (a!=b):\n",
" wrong.append({'query':conv['value'],'model':a,'gt':b})\n",
" print(conv['value'])\n",
" print(a)\n",
" print(b)\n",
" print(model_out[1:])\n",
" print('------------')\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"36"
]
},
"execution_count": 44,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import ctypes\n",
"import json\n",
"import platform\n",
"\n",
"lib_path = './postprocess.so'\n",
"lib = ctypes.CDLL(lib_path)\n",
"lib.postprocess.argtypes = [ctypes.c_char_p, ctypes.c_char_p]\n",
"lib.postprocess.restype = ctypes.c_char_p\n",
"\n",
"lib.free_string.argtypes = [ctypes.c_char_p]\n",
"\n",
"def process(query,pred_class):\n",
"\n",
" query_bytes = query.encode('utf-8')\n",
" pred_class_bytes = pred_class.encode('utf-8')\n",
"\n",
" result_ptr = lib.postprocess(query_bytes, pred_class_bytes)\n",
"\n",
" if not result_ptr:\n",
" print(\"C++ return empty\")\n",
" result_json = None\n",
" else:\n",
" # 將 C++ 回傳的 char* 轉換為 Python 字串\n",
" result_str = ctypes.string_at(result_ptr).decode('utf-8')\n",
" print(f\"C++ return:\")\n",
" print(result_str)\n",
" \n",
" # 解析 JSON\n",
" result_json = json.loads(result_str)\n",
"\n",
" return json.dumps(result_json, indent=4, ensure_ascii=False)"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 5000/5000 [00:00<00:00, 60459.13it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"風開大一點\n",
"{'name': 'control_car_properties', 'arguments': {'propertyId': 'HVAC_FAN_SPEED', 'areaId': '', 'operation': 'increase', 'value': '1'}}\n",
"-----\n",
"風開大一點\n",
"{'name': 'control_car_properties', 'arguments': {'propertyId': 'HVAC_FAN_SPEED', 'areaId': '', 'operation': 'increase', 'value': '1'}}\n",
"-----\n",
"幫我把風關小\n",
"{'name': 'control_car_properties', 'arguments': {'propertyId': 'HVAC_FAN_SPEED', 'areaId': '', 'operation': 'decrease', 'value': '1'}}\n",
"-----\n",
"幫我把風開大\n",
"{'name': 'control_car_properties', 'arguments': {'propertyId': 'HVAC_FAN_SPEED', 'areaId': '', 'operation': 'increase', 'value': '1'}}\n",
"-----\n",
"超級熱到流汗停不下來\n",
"{'name': 'control_car_properties', 'arguments': {'propertyId': 'HVAC_TEMPERATURE_SET', 'areaId': '', 'operation': 'set', 'value': '17'}}\n",
"-----\n",
"把風開強點\n",
"{'name': 'control_car_properties', 'arguments': {'propertyId': 'HVAC_FAN_SPEED', 'areaId': '', 'operation': 'increase', 'value': '1'}}\n",
"-----\n",
"幫我把風關小\n",
"{'name': 'control_car_properties', 'arguments': {'propertyId': 'HVAC_FAN_SPEED', 'areaId': '', 'operation': 'decrease', 'value': '1'}}\n",
"-----\n",
"幫我把風關小\n",
"{'name': 'control_car_properties', 'arguments': {'propertyId': 'HVAC_FAN_SPEED', 'areaId': '', 'operation': 'decrease', 'value': '1'}}\n",
"-----\n",
"幫我把風關小\n",
"{'name': 'control_car_properties', 'arguments': {'propertyId': 'HVAC_FAN_SPEED', 'areaId': '', 'operation': 'decrease', 'value': '1'}}\n",
"-----\n",
"熱到冒汗不停\n",
"{'name': 'control_car_properties', 'arguments': {'propertyId': 'HVAC_TEMPERATURE_SET', 'areaId': '', 'operation': 'set', 'value': '17'}}\n",
"-----\n",
"幫我把風開大\n",
"{'name': 'control_car_properties', 'arguments': {'propertyId': 'HVAC_FAN_SPEED', 'areaId': '', 'operation': 'increase', 'value': '1'}}\n",
"-----\n",
"超級熱到流汗停不下來\n",
"{'name': 'control_car_properties', 'arguments': {'propertyId': 'HVAC_TEMPERATURE_SET', 'areaId': '', 'operation': 'set', 'value': '17'}}\n",
"-----\n",
"冷到開暖氣都沒用\n",
"{'name': 'control_car_properties', 'arguments': {'propertyId': 'HVAC_TEMPERATURE_SET', 'areaId': '', 'operation': 'set', 'value': '32'}}\n",
"-----\n",
"幫我把風開大\n",
"{'name': 'control_car_properties', 'arguments': {'propertyId': 'HVAC_FAN_SPEED', 'areaId': '', 'operation': 'increase', 'value': '1'}}\n",
"-----\n",
"把風關小\n",
"{'name': 'control_car_properties', 'arguments': {'propertyId': 'HVAC_FAN_SPEED', 'areaId': '', 'operation': 'decrease', 'value': '1'}}\n",
"-----\n",
"風開大一點\n",
"{'name': 'control_car_properties', 'arguments': {'propertyId': 'HVAC_FAN_SPEED', 'areaId': '', 'operation': 'increase', 'value': '1'}}\n",
"-----\n",
"把風關小\n",
"{'name': 'control_car_properties', 'arguments': {'propertyId': 'HVAC_FAN_SPEED', 'areaId': '', 'operation': 'decrease', 'value': '1'}}\n",
"-----\n",
"幫我把風關小\n",
"{'name': 'control_car_properties', 'arguments': {'propertyId': 'HVAC_FAN_SPEED', 'areaId': '', 'operation': 'decrease', 'value': '1'}}\n",
"-----\n",
"冷到開暖氣都沒用\n",
"{'name': 'control_car_properties', 'arguments': {'propertyId': 'HVAC_TEMPERATURE_SET', 'areaId': '', 'operation': 'set', 'value': '32'}}\n",
"-----\n",
"幫我把風開大\n",
"{'name': 'control_car_properties', 'arguments': {'propertyId': 'HVAC_FAN_SPEED', 'areaId': '', 'operation': 'increase', 'value': '1'}}\n",
"-----\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\n"
]
},
{
"data": {
"text/plain": [
"{'HVAC_FAN_SPEED', 'HVAC_TEMPERATURE_SET', 'POWER_SUNSHADE', 'WINDOW_POS'}"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from tqdm import tqdm\n",
"pid = set()\n",
"for data in tqdm(ctrl):\n",
" for idx,conv in enumerate(data['conversations']):\n",
" if conv['from']=='human' and data['conversations'][idx+1]['from']=='function_call':\n",
" b = json.loads(data['conversations'][idx+1]['value'].replace('兩','2'))[0]\n",
" \n",
" if 'value' in b['arguments'] and str(b['arguments']['value']).isdigit() and any([sk in conv['value'] for sk in switch_keywords]):\n",
" pid.add(b['arguments']['propertyId'])\n",
" if b['arguments']['propertyId'] in ['HVAC_FAN_SPEED', 'HVAC_TEMPERATURE_SET']:\n",
" print(conv['value'])\n",
" print(b)\n",
" print('-----')\n",
"pid"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[{'name': 'control_car_properties',\n",
" 'arguments': {'propertyId': 'WINDOW_POS',\n",
" 'areaId': 'SEAT_ROW_2_LEFT',\n",
" 'operation': 'increase'}}]"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"b"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "py10",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.16"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
|