{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "cc06fe17-c615-453a-9d54-b04f861ee732", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from dotenv import load_dotenv, find_dotenv\n", "load_dotenv(find_dotenv())" ] }, { "cell_type": "code", "execution_count": 2, "id": "9495c8de-b218-436b-8145-78b222ed4545", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'\\n\\nA large language model is a type of artificial intelligence (AI) system that uses a large set of text data to generate text-based predictions and generate new data.'" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from langchain.llms import OpenAI\n", "llm = OpenAI(model_name=\"text-davinci-003\")\n", "llm(\"explain large language model in one sentence\")" ] }, { "cell_type": "code", "execution_count": 5, "id": "3cf04b99-b937-4fec-a5f1-093b638245b9", "metadata": {}, "outputs": [], "source": [ "from langchain.schema import (\n", " AIMessage,\n", " HumanMessage,\n", " SystemMessage\n", ")\n", "from langchain.chat_models import ChatOpenAI" ] }, { "cell_type": "code", "execution_count": 6, "id": "6b42d0b0-d353-483f-994c-0ae45af8e7f8", "metadata": {}, "outputs": [], "source": [ "chat = ChatOpenAI(model_name=\"gpt-3.5-turbo\", temperature=0.3)\n", "messages= [\n", " SystemMessage(content=\"You are an expert data scientist\"),\n", " HumanMessage(content=\"Write a python script that trains a neural network on stimulated data\")\n", "]\n", "response=chat(messages)" ] }, { "cell_type": "code", "execution_count": 7, "id": "3b07b556-21cc-4c36-9d80-4f1fd2d83cba", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Sure! Here's an example of a Python script that trains a neural network on simulated data using the Keras library:\n", "\n", "```python\n", "import numpy as np\n", "from keras.models import Sequential\n", "from keras.layers import Dense\n", "\n", "# Generate simulated data\n", "np.random.seed(0)\n", "X = np.random.rand(100, 2)\n", "y = np.random.randint(2, size=100)\n", "\n", "# Define the neural network model\n", "model = Sequential()\n", "model.add(Dense(10, input_dim=2, activation='relu'))\n", "model.add(Dense(1, activation='sigmoid'))\n", "\n", "# Compile the model\n", "model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])\n", "\n", "# Train the model\n", "model.fit(X, y, epochs=10, batch_size=10)\n", "\n", "# Evaluate the model\n", "loss, accuracy = model.evaluate(X, y)\n", "print(f\"Loss: {loss}, Accuracy: {accuracy}\")\n", "```\n", "\n", "In this script, we first generate simulated data using `np.random.rand()` and `np.random.randint()` functions. The input data `X` is a 2-dimensional array of random values between 0 and 1, and the target labels `y` are binary values (0 or 1).\n", "\n", "We then define a simple neural network model using the `Sequential` class from Keras. It consists of a single hidden layer with 10 neurons and a ReLU activation function, followed by an output layer with a single neuron and a sigmoid activation function.\n", "\n", "The model is compiled with the binary cross-entropy loss function and the Adam optimizer. We then train the model using the `fit()` function, specifying the number of epochs and batch size.\n", "\n", "Finally, we evaluate the trained model on the same data and print the loss and accuracy.\n" ] } ], "source": [ "print(response.content, end='\\n')" ] }, { "cell_type": "code", "execution_count": null, "id": "30193256-290b-4c90-b91c-33ae893a271d", "metadata": {}, "outputs": [], "source": [] } ], "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.11.4" } }, "nbformat": 4, "nbformat_minor": 5 }