emrulphy commited on
Commit
fdb4d9f
1 Parent(s): a728519

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +28 -21
README.md CHANGED
@@ -60,27 +60,34 @@ model = PaliGemmaForConditionalGeneration.from_pretrained(
60
  processor = AutoProcessor.from_pretrained(model_id)processor = AutoProcessor.from_pretrained(model_id)
61
 
62
  ### Model inputs and ouputs
63
- headine="headline of the news article"
64
- article="News body text"
65
- img_path="Path of the image"
66
- image=Image.open(img_path).convert('RGB')
67
- prompt=f"""You are a news classifer AI assitant. You are given with a news article that contains headline, body text and image.
68
- Your task is to analyze the headline, body text and image, and classify the news as biased or unbiased.
69
-
70
- In this particular task, the term 'biased' represents disinformation, propaganda, loaded language, negative associations, generalization, harm, hatred, satire\
71
- whereas 'unbiased' represents real news without the spread of misinformation, disinformation, and propaganda.\
72
-
73
- headlines: {headline}
74
- news body text: {article}.
75
- What would be the label for this news article considering features from both texts and image?
76
- """
77
-
78
- model_inputs = processor(text=prompt, images=image, return_tensors="pt").to(model.device)
79
- input_len = model_inputs["input_ids"].shape[-1]
80
- generation = model.generate(**model_inputs, max_new_tokens=20, do_sample=False)
81
- generation = generation[0][input_len:]
82
- label = processor.decode(generation, skip_special_tokens=True)
83
- print(label)
 
 
 
 
 
 
 
84
 
85
  ###
86
 
 
60
  processor = AutoProcessor.from_pretrained(model_id)processor = AutoProcessor.from_pretrained(model_id)
61
 
62
  ### Model inputs and ouputs
63
+ img_path="Enter your image file driectory"
64
+ text_path="Enter article data path like csv file with image file names and corresponding news articles"
65
+ df = pd.read_csv(text_path)
66
+
67
+ for idx, row in test_df.iterrows():
68
+ img=row['image_filename'] # image file names in the csv file
69
+
70
+ headine=row['Headline'] # take the headline columns from the csv files.
71
+ article=row['article'] # article names
72
+ img_path=img_dir+f"/{img}" #full path of the image
73
+ image=Image.open(img_path).convert('RGB')
74
+ prompt=f"""You are a news classifer AI assitant. You are given with a news article that contains headline, body text and image.
75
+ Your task is to analyze the headline, body text and image, and classify the news as biased or unbiased.
76
+
77
+ In this particular task, the term 'biased' represents disinformation, propaganda, loaded language, negative associations, generalization, harm, hatred, satire\
78
+ whereas 'unbiased' represents real news without the spread of misinformation, disinformation, and propaganda.\
79
+
80
+ headlines: {headline}
81
+ news body text: {article}.
82
+ What would be the label for this news article considering features from both texts and image?
83
+ """
84
+
85
+ model_inputs = processor(text=prompt, images=image, return_tensors="pt").to(model.device)
86
+ input_len = model_inputs["input_ids"].shape[-1]
87
+ generation = model.generate(**model_inputs, max_new_tokens=20, do_sample=False)
88
+ generation = generation[0][input_len:]
89
+ label = processor.decode(generation, skip_special_tokens=True)
90
+ print(label)
91
 
92
  ###
93