shing12345 commited on
Commit
aaaf3bd
·
verified ·
1 Parent(s): 080cde1

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +43 -4
README.md CHANGED
@@ -13,7 +13,46 @@ datasets:
13
  language:
14
  - en
15
  library_name: transformers
16
- base_model:
17
- - Falconsai/text_summarization
18
- - meta-llama/Meta-Llama-3.1-8B-Instruct
19
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  language:
14
  - en
15
  library_name: transformers
16
+ ---
17
+ import torch
18
+ from transformers import BartForConditionalGeneration, BartTokenizer
19
+
20
+ class AdvancedSummarizer:
21
+ def __init__(self, model_name="facebook/bart-large-cnn"):
22
+ self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
23
+ self.model = BartForConditionalGeneration.from_pretrained(model_name).to(self.device)
24
+ self.tokenizer = BartTokenizer.from_pretrained(model_name)
25
+
26
+ def summarize(self, text, max_length=150, min_length=50, length_penalty=2.0, num_beams=4):
27
+ inputs = self.tokenizer([text], max_length=1024, return_tensors="pt", truncation=True)
28
+ inputs = inputs.to(self.device)
29
+
30
+ summary_ids = self.model.generate(
31
+ inputs["input_ids"],
32
+ num_beams=num_beams,
33
+ max_length=max_length,
34
+ min_length=min_length,
35
+ length_penalty=length_penalty
36
+ )
37
+
38
+ summary = self.tokenizer.decode(summary_ids[0], skip_special_tokens=True)
39
+ return summary
40
+
41
+ def main():
42
+ # Example usage
43
+ summarizer = AdvancedSummarizer()
44
+
45
+ text = """
46
+ Artificial intelligence (AI) is intelligence demonstrated by machines, as opposed to natural intelligence displayed by animals including humans. AI research has been defined as the field of study of intelligent agents, which refers to any system that perceives its environment and takes actions that maximize its chance of achieving its goals.
47
+
48
+ The term "artificial intelligence" had previously been used to describe machines that mimic and display "human" cognitive skills that are associated with the human mind, such as "learning" and "problem-solving". This definition has since been rejected by major AI researchers who now describe AI in terms of rationality and acting rationally, which does not limit how intelligence can be articulated.
49
+
50
+ AI applications include advanced web search engines, recommendation systems, understanding human speech, self-driving cars, automated decision-making and competing at the highest level in strategic game systems. As machines become increasingly capable, tasks considered to require "intelligence" are often removed from the definition of AI, a phenomenon known as the AI effect. For instance, optical character recognition is frequently excluded from things considered to be AI, having become a routine technology.
51
+ """
52
+
53
+ summary = summarizer.summarize(text)
54
+ print("Summary:")
55
+ print(summary)
56
+
57
+ if __name__ == "__main__":
58
+ main()