Corrigan123 commited on
Commit
10f17ec
1 Parent(s): 67af35d
Files changed (3) hide show
  1. app.py +52 -0
  2. test.txt.txt +0 -0
  3. training.txt.txt +21 -0
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import GPT2Tokenizer, GPT2LMHeadModel, Trainer, TrainingArguments
2
+ from datasets import load_dataset
3
+
4
+ # Load the text dataset from the specified file.
5
+ dataset = load_dataset("text", data_files="training.txt")
6
+
7
+ # Initialize the GPT-2 tokenizer.
8
+ tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
9
+ # Set the tokenizer's pad token to the EOS token.
10
+ tokenizer.pad_token = tokenizer.eos_token
11
+
12
+ # Define a function to tokenize the dataset and prepare labels.
13
+ def tokenize_function(examples):
14
+ # Tokenize the text to input_ids, attention_mask
15
+ tokenized_inputs = tokenizer(examples["text"], padding="max_length", truncation=True, max_length=512)
16
+ # Prepare labels: labels are the same as input_ids for language modeling
17
+ tokenized_inputs["labels"] = tokenized_inputs["input_ids"].copy()
18
+ return tokenized_inputs
19
+
20
+ # Tokenize the entire dataset.
21
+ tokenized_datasets = dataset.map(tokenize_function, batched=True)
22
+ # Remove the 'text' column as it's no longer needed after tokenization.
23
+ tokenized_datasets = tokenized_datasets.remove_columns(["text"])
24
+ # Set the format of the dataset to PyTorch tensors.
25
+ tokenized_datasets.set_format(type="torch", columns=["input_ids", "attention_mask", "labels"])
26
+
27
+ # Load the GPT-2 model.
28
+ model = GPT2LMHeadModel.from_pretrained("gpt2")
29
+
30
+ # Define training arguments.
31
+ training_args = TrainingArguments(
32
+ output_dir="./output",
33
+ overwrite_output_dir=True,
34
+ num_train_epochs=3,
35
+ per_device_train_batch_size=4,
36
+ save_steps=10_000,
37
+ save_total_limit=2,
38
+ )
39
+
40
+ # Initialize the Trainer with the training dataset including labels.
41
+ trainer = Trainer(
42
+ model=model,
43
+ args=training_args,
44
+ train_dataset=tokenized_datasets["train"],
45
+ )
46
+
47
+ # Start the training process.
48
+ trainer.train()
49
+
50
+ # Save the fine-tuned model and tokenizer.
51
+ model.save_pretrained("fine_tuned_gpt2_model")
52
+ tokenizer.save_pretrained("fine_tuned_gpt2_model")
test.txt.txt DELETED
File without changes
training.txt.txt ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Fitness and nutrition play crucial roles in maintaining a healthy lifestyle. Regular exercise and balanced nutrition contribute to physical well-being and overall health. Here's some foundational information to help you understand the importance of fitness and nutrition:
2
+
3
+ Exercise:
4
+ Regular physical activity is essential for maintaining a healthy weight, reducing the risk of chronic diseases, and improving overall well-being. It includes activities such as cardio, strength training, flexibility exercises, and balance training.
5
+
6
+ Cardiovascular exercises, like walking, running, swimming, and cycling, improve heart health and stamina. Strength training exercises, such as weightlifting and bodyweight exercises, help build muscle strength and bone density. Flexibility exercises, like stretching and yoga, enhance joint mobility and reduce the risk of injury. Balance training exercises, such as yoga poses and stability exercises, improve balance and coordination.
7
+
8
+ Nutrition:
9
+ Eating a balanced diet is vital for providing essential nutrients, maintaining energy levels, and supporting overall health. A balanced diet includes a variety of foods from all food groups, such as fruits, vegetables, whole grains, lean proteins, and healthy fats.
10
+
11
+ Fruits and vegetables are rich in vitamins, minerals, and antioxidants that support immune function and reduce the risk of chronic diseases. Whole grains provide fiber, which aids digestion and helps regulate blood sugar levels. Lean proteins, such as poultry, fish, beans, and tofu, provide essential amino acids for muscle repair and growth. Healthy fats, like those found in avocados, nuts, seeds, and olive oil, support heart health and brain function.
12
+
13
+ Hydration:
14
+ Staying hydrated is crucial for overall health and performance. Water is essential for regulating body temperature, transporting nutrients, and removing waste products from the body. Aim to drink plenty of water throughout the day, especially before, during, and after exercise.
15
+
16
+ Meal Timing:
17
+ Eating regular meals and snacks throughout the day helps maintain energy levels and prevents overeating. Aim to eat a balanced meal or snack every 3-4 hours to keep your metabolism running smoothly and stabilize blood sugar levels.
18
+
19
+ Portion Control:
20
+ Practicing portion control helps prevent overeating and promotes weight management. Use visual cues, like measuring cups and portion plates, to help you control portion sizes and avoid mindless eating.
21
+