ayjays132 commited on
Commit
0417d9a
1 Parent(s): 123b9f6

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +46 -1
README.md CHANGED
@@ -1,4 +1,49 @@
1
  ---
2
  license: apache-2.0
3
  library_name: transformers
4
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: apache-2.0
3
  library_name: transformers
4
+ ---
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+ from transformers import BartTokenizer, BartForConditionalGeneration
13
+ from datasets import load_dataset
14
+
15
+ # Load pre-trained BART model for summarization
16
+ tokenizer = BartTokenizer.from_pretrained('ayjays132/EnhancerModel')
17
+ model = BartForConditionalGeneration.from_pretrained('ayjays132/EnhancerModel')
18
+
19
+ # Load dataset
20
+ dataset = load_dataset("cnn_dailymail", "3.0.0")
21
+
22
+ # Function to generate summary
23
+ def summarize(text):
24
+ inputs = tokenizer(text, return_tensors="pt", max_length=1024, truncation=True)
25
+ summary_ids = model.generate(inputs['input_ids'], max_length=150, min_length=40, length_penalty=2.0, num_beams=4, early_stopping=True)
26
+ return tokenizer.decode(summary_ids[0], skip_special_tokens=True)
27
+
28
+ # Debugging: Print the type and content of the first example
29
+ print("Type of dataset['test']:", type(dataset['test']))
30
+ print("Type of the first element in dataset['test']:", type(dataset['test'][0]))
31
+ print("Content of the first element in dataset['test']:", dataset['test'][0])
32
+
33
+ # Test the model on a few examples
34
+ for example in dataset['test'][:5]:
35
+ try:
36
+ # If the example is a string, then it's likely that 'dataset['test']' is not loaded as expected
37
+ if isinstance(example, str):
38
+ print(f"Article: {example}\n")
39
+ print(f"Summary: {summarize(example)}\n")
40
+ else:
41
+ # Access the 'article' field if the example is a dictionary
42
+ article = example.get('article', None)
43
+ if article:
44
+ print(f"Article: {article}\n")
45
+ print(f"Summary: {summarize(article)}\n")
46
+ else:
47
+ print("No 'article' field found in this example.")
48
+ except Exception as e:
49
+ print(f"Error processing example: {e}")