TomSmail commited on
Commit
ea1b084
1 Parent(s): 049998e

create: new pay file from collar

Browse files
Files changed (1) hide show
  1. psy.ipynb +77 -14
psy.ipynb CHANGED
@@ -1,20 +1,83 @@
1
  {
2
- "metadata" : {
3
- "signature": "hex-digest",
4
- "kernel_info": {
5
-
6
- "name" : "the name of the kernel"
 
 
 
 
7
  },
8
  "language_info": {
9
-
10
- "name" : "the programming language of the kernel",
11
- "version": "the version of the language",
12
- "codemirror_mode": "The name of the codemirror mode to use [optional]"
13
  }
14
  },
15
- "nbformat": 4,
16
- "nbformat_minor": 0,
17
- "cells" : [
18
-
19
- ],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  }
 
1
  {
2
+ "nbformat": 4,
3
+ "nbformat_minor": 0,
4
+ "metadata": {
5
+ "colab": {
6
+ "provenance": []
7
+ },
8
+ "kernelspec": {
9
+ "name": "python3",
10
+ "display_name": "Python 3"
11
  },
12
  "language_info": {
13
+ "name": "python"
 
 
 
14
  }
15
  },
16
+ "cells": [
17
+ {
18
+ "cell_type": "code",
19
+ "execution_count": null,
20
+ "metadata": {
21
+ "id": "IAGKskIWS9C0"
22
+ },
23
+ "outputs": [],
24
+ "source": [
25
+ "from datasets import load_dataset\n",
26
+ "from transformers import AutoTokenizer, AutoModelForSequenceClassification, TrainingArguments, Trainer\n",
27
+ "import numpy as np\n",
28
+ "import evaluate\n",
29
+ "\n",
30
+ "\n",
31
+ "DATA_SEED = 9843203\n",
32
+ "QUICK_TEST = True\n",
33
+ "\n",
34
+ "# This is our baseline dataset\n",
35
+ "dataset = load_dataset(\"ClaudiaRichard/mbti_classification_v2\")\n",
36
+ "\n",
37
+ "# LLama3 8b\n",
38
+ "tokeniser = AutoTokenizer.from_pretrained(\"meta-llama/Meta-Llama-3-8B\")\n",
39
+ "\n",
40
+ "def tokenise_function(examples):\n",
41
+ " return tokeniser(examples[\"text\"], padding=\"max_length\", truncation=True)\n",
42
+ "\n",
43
+ "tokenised_dataset = dataset.map(tokenise_function, batched=True)\n",
44
+ "\n",
45
+ "\n",
46
+ "# Different sized datasets will allow for different training times\n",
47
+ "train_dataset = tokenised_datasets[\"train\"].shuffle(seed=DATA_SEED).select(range(1000)) if QUICK_TEST else tokenised_datasets[\"train\"].shuffle(seed=DATA_SEED)\n",
48
+ "test_dataset = tokenised_datasets[\"test\"].shuffle(seed=DATA_SEED).select(range(1000)) if QUICK_TEST else tokenised_datasets[\"test\"].shuffle(seed=DATA_SEED)\n",
49
+ "\n",
50
+ "\n",
51
+ "# Each of our Mtbi types has a specific label here\n",
52
+ "model = AutoModelForSequenceClassification.from_pretrained(\"meta-llama/Meta-Llama-3-8B\", num_labels=16)\n",
53
+ "\n",
54
+ "# Using default hyperparameters at the moment\n",
55
+ "training_args = TrainingArguments(output_dir=\"test_trainer\")\n",
56
+ "\n",
57
+ "# A default metric for checking accuracy\n",
58
+ "metric = evaluate.load(\"accuracy\")\n",
59
+ "\n",
60
+ "def compute_metrics(eval_pred):\n",
61
+ " logits, labels = eval_pred\n",
62
+ " predictions = np.argmax(logits, axis=-1)\n",
63
+ " return metric.compute(predictions=predictions, references=labels)\n",
64
+ "\n",
65
+ "# Extract arguments from training\n",
66
+ "training_args = TrainingArguments(output_dir=\"test_trainer\", evaluation_strategy=\"epoch\")\n",
67
+ "\n",
68
+ "# Builds a training object using previously defined data\n",
69
+ "trainer = Trainer(\n",
70
+ " model=model,\n",
71
+ " args=training_args,\n",
72
+ " train_dataset=train_dataset,\n",
73
+ " eval_dataset=test_dataset,\n",
74
+ " compute_metrics=compute_metrics,\n",
75
+ ")\n",
76
+ "\n",
77
+ "# Finally, fine-tune!\n",
78
+ "if __name__ == \"__main__\":\n",
79
+ " trainer.train()"
80
+ ]
81
+ }
82
+ ]
83
  }