Update README.md
Browse files
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 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
label
|
83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
|