Spaces:
Runtime error
Runtime error
File size: 4,726 Bytes
886d623 120efdc 886d623 120efdc 886d623 120efdc 886d623 120efdc 886d623 120efdc 886d623 |
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 |
{
"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
}
|