{ "cells": [ { "cell_type": "code", "execution_count": 3, "id": "a0cd5176", "metadata": {}, "outputs": [], "source": [ "# !wget https://huggingface.co/datasets/malaysia-ai/motomalaysia.com-multiturn/resolve/main/motomalaysia-data.jsonl.translated\n", "# !wget https://huggingface.co/datasets/malaysia-ai/motomalaysia.com-multiturn/resolve/main/motomalaysia-data.jsonl" ] }, { "cell_type": "code", "execution_count": 4, "id": "b94471a6", "metadata": {}, "outputs": [], "source": [ "import json" ] }, { "cell_type": "code", "execution_count": 5, "id": "a69c193d", "metadata": {}, "outputs": [], "source": [ "with open('motomalaysia-data.jsonl') as fopen:\n", " for l in fopen:\n", " l = json.loads(l)\n", " break" ] }, { "cell_type": "code", "execution_count": 9, "id": "2907e6bd", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'\\n{\"image\": \"pic/0.jpg\", \"conversations\": [{\"role\": \"user\", \"content\": \"Ini makanan apa?\"}, {\"role\": \"assistant\", \"content\": \"Ini ialah Kuih Siput.\"},\\n'" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\"\"\"\n", "{\"image\": \"pic/0.jpg\", \"conversations\": [{\"role\": \"user\", \"content\": \"Ini makanan apa?\"}, {\"role\": \"assistant\", \"content\": \"Ini ialah Kuih Siput.\"},\n", "\"\"\"" ] }, { "cell_type": "code", "execution_count": 21, "id": "41632e47", "metadata": {}, "outputs": [], "source": [ "chats = []\n", "with open('motomalaysia-data.jsonl.translated') as fopen:\n", " for l in fopen:\n", " l = json.loads(l)\n", " overview = l['specs']['overview_translated']\n", " overview = [s for s in overview if s]\n", " overview = '\\n'.join(overview)\n", " spec = '\\n'.join(l['specs']['specs'])\n", " conversations = []\n", " conversations.extend([\n", " {\"role\": \"user\", \"content\": \"Ini model apa?\"},\n", " {\"role\": \"assistant\", \"content\": l['specs']['model_name']},\n", " ])\n", " if len(overview):\n", " conversations.extend([\n", " {\"role\": \"user\", \"content\": \"apa kelebihan moto tu?\"},\n", " {\"role\": \"assistant\", \"content\": overview},\n", " ])\n", " conversations.extend([\n", " {\"role\": \"user\", \"content\": \"apa spesifikasi moto tu?\"},\n", " {\"role\": \"assistant\", \"content\": spec},\n", " ])\n", " chats.append({\n", " 'image': l['local_image'],\n", " 'image_url': l['img_url'],\n", " 'conversations': conversations\n", " })" ] }, { "cell_type": "code", "execution_count": 23, "id": "94cd0f04", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'image': 'pic/Yamaha NMAX (2016)_1.jpg',\n", " 'image_url': 'https://www.motomalaysia.com/wp-content/uploads/2017/10/yamaha-nmax-2.jpg',\n", " 'conversations': [{'role': 'user', 'content': 'Ini model apa?'},\n", " {'role': 'assistant', 'content': 'Yamaha NMAX (2016)'},\n", " {'role': 'user', 'content': 'apa spesifikasi moto tu?'},\n", " {'role': 'assistant',\n", " 'content': 'Manufacturer: Yamaha\\nModel: 2016\\nGeneration: \\nYamaha NMAX (2016)\\n\\nType: Scooter\\nColour Available: \\n\\n Grey\\n Red\\n\\n\\nDimension: 1,955 x 740 x 1,115 mm\\nWheelbase: 1,350 mm\\nWeight: 136 kg\\nSeat Height: 765 mm\\nGround Clearance: 135 mm\\nMeter Display: \\n\\nDigital - Speedometer, Fuel Gauge\\n\\n\\nEngine: 4-Stroke, SOHC\\nDisplacement: 155 CC\\nNo Of Cylinders: 1-Cylinder\\nCompression Ratio: 10.5 : 1\\nBore x Stroke: 58mm x 58.7mm\\nMax Power: 11.1 kW @ 8,000 RPM\\nMax Torque: 14.4 Nm @ 6,000 RPM\\nMax Speed: -\\nTransmission: Automatic, CVT\\nClutch: Dry, centrifugal, Shoe\\nIgnition System: Transistor Coil Ignition (TCI)\\nStarting System: Electric Starter\\nCooling System: Liquid Cooled\\nCarburetor: -\\nFuel System: Fuel Injection\\nFuel Capacity: 6.6 Liters\\nFuel Consumption: -\\nOil Capacity: 1.0 Liters\\nFeatures: -\\nType: Underbone\\nFront Suspension: Telescopic\\nRear Suspension: Unit Swing\\nFront Brake: Disc\\nRear Brake: Disc\\nFront Tire: 110/70-13\\nRear Tire: 130/70-13\\nFront Wheel: -\\nRear Wheel: -\\nUnder Seat Box: -'}]}" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "chats[-2]" ] }, { "cell_type": "code", "execution_count": 24, "id": "75464efe", "metadata": {}, "outputs": [], "source": [ "with open('motomalaysia-chat.json', 'w') as fopen:\n", " json.dump(chats, fopen)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.8.10" } }, "nbformat": 4, "nbformat_minor": 5 }