Update README.md
Browse files
README.md
CHANGED
|
@@ -36,6 +36,43 @@ which was the most upvoted comment. If you ask me, I did not expect it to be tha
|
|
| 36 |
|
| 37 |
There are more examples I tried that were "approved" by the community, however it's not always the case and it depends on a lot more things that are out of the commenter's control, such as the popularity of the post and timing. In general, for most posts I've tried the comments generated were reasonable for my expectations.
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
### Model Description
|
| 40 |
I fine tuned the model using a sample of popular comments from posts that I extracted using Reddit's python API.
|
| 41 |
I started with comments with > 10 upvotes and did some basic filtering, removing long and low quality comments based on my personal standards. About 3% of the model's parameters were trainable. I used 1.5k posts and 12k total comments as training data.
|
|
@@ -44,26 +81,9 @@ The prompt was pretty vanilla, without any carefully crafted prompt engineering
|
|
| 44 |
You may notice that this repo has a v4 in the title, that's because I tried this training a number of times but I tried my best to filter the training data as much as possible, without greatly affecting the goal of getting upvotes.
|
| 45 |
This decision was made after the previous versions ended up producing text that was pure misinformation or inappropriate. I thought it would be best to avoid extreme cases so I did not make the other versions public. Still, the text produced is likely to be weird (for the lack of a better word), given that the language model was exposed to popular Reddit comments. Also, I filtered out posts that one might consider controversial that were quite popular in the last few days.
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
| 49 |
- **Developed by:** me
|
| 50 |
-
- **Funded by
|
| 51 |
-
|
| 52 |
-
### Model Sources [optional]
|
| 53 |
-
|
| 54 |
-
<!-- Provide the basic links for the model. -->
|
| 55 |
-
|
| 56 |
-
- **Repository:** [More Information Needed]
|
| 57 |
-
- **Paper [optional]:** [More Information Needed]
|
| 58 |
-
- **Demo [optional]:** [More Information Needed]
|
| 59 |
|
| 60 |
## Uses
|
| 61 |
|
| 62 |
-
For fun and for limit testing text imprinted on images, commonly found in memes :)
|
| 63 |
-
|
| 64 |
-
## How to Get Started with the Model
|
| 65 |
-
|
| 66 |
-
Use the code below to get started with the model
|
| 67 |
-
Coming soon
|
| 68 |
-
|
| 69 |
-
- PEFT 0.14.0
|
|
|
|
| 36 |
|
| 37 |
There are more examples I tried that were "approved" by the community, however it's not always the case and it depends on a lot more things that are out of the commenter's control, such as the popularity of the post and timing. In general, for most posts I've tried the comments generated were reasonable for my expectations.
|
| 38 |
|
| 39 |
+
### How to Get Started with the Model
|
| 40 |
+
|
| 41 |
+
Use the code below to get started with the model
|
| 42 |
+
|
| 43 |
+
```python
|
| 44 |
+
from peft import PeftModel, PeftConfig
|
| 45 |
+
from transformers import AutoProcessor, LlavaForConditionalGeneration
|
| 46 |
+
from PIL import Image
|
| 47 |
+
import torch
|
| 48 |
+
|
| 49 |
+
# Load the original model and processor (This parts downloads Pixtral-12B)
|
| 50 |
+
model_id = "mistral-community/pixtral-12b"
|
| 51 |
+
model = LlavaForConditionalGeneration.from_pretrained(model_id, torch_dtype=torch.float16, device_map="cuda") # Or "mps" for MacOS or "auto" for multiple Nvidia GPUs
|
| 52 |
+
processor = AutoProcessor.from_pretrained(model_id)
|
| 53 |
+
|
| 54 |
+
# Load the LoRA configuration (This parts downloads current repo)
|
| 55 |
+
peft_config = PeftConfig.from_pretrained("AlexandrosChariton/reddit-pixtral-12B-Lora-v4")
|
| 56 |
+
lora_model = PeftModel.from_pretrained(model, "AlexandrosChariton/reddit-pixtral-12B-Lora-v4")
|
| 57 |
+
|
| 58 |
+
# You need a meme in image format to run the model
|
| 59 |
+
image_path = "meme_image.png" # or webp, jpg, jpeg
|
| 60 |
+
image_path = "seriously-how-are-you-doing-this-v0-n7drhacsba6e1.webp"
|
| 61 |
+
meme_title = "I hate it when this happens to me"
|
| 62 |
+
|
| 63 |
+
# Resize image to 512x512. This is not necessary but I used 512x512 during training
|
| 64 |
+
image = Image.open(image_path).convert("RGB")
|
| 65 |
+
image.thumbnail((512, 512))
|
| 66 |
+
|
| 67 |
+
# Chat template is applied to the prompt manually here
|
| 68 |
+
PROMPT = f"<s>[INST]Come up with a comment that will get upvoted by the community for a reddit post in r/memes. Provide the comment body with text and nothing else. The post has title: '{meme_title}' and image:\n[IMG][/INST]"
|
| 69 |
+
inputs = processor(text=PROMPT, images=image, return_tensors="pt").to("cuda") # or "mps" for MacOS
|
| 70 |
+
|
| 71 |
+
generate_ids = lora_model.generate(**inputs, max_new_tokens=650)
|
| 72 |
+
output = processor.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
|
| 73 |
+
print(output)
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
### Model Description
|
| 77 |
I fine tuned the model using a sample of popular comments from posts that I extracted using Reddit's python API.
|
| 78 |
I started with comments with > 10 upvotes and did some basic filtering, removing long and low quality comments based on my personal standards. About 3% of the model's parameters were trainable. I used 1.5k posts and 12k total comments as training data.
|
|
|
|
| 81 |
You may notice that this repo has a v4 in the title, that's because I tried this training a number of times but I tried my best to filter the training data as much as possible, without greatly affecting the goal of getting upvotes.
|
| 82 |
This decision was made after the previous versions ended up producing text that was pure misinformation or inappropriate. I thought it would be best to avoid extreme cases so I did not make the other versions public. Still, the text produced is likely to be weird (for the lack of a better word), given that the language model was exposed to popular Reddit comments. Also, I filtered out posts that one might consider controversial that were quite popular in the last few days.
|
| 83 |
|
|
|
|
|
|
|
| 84 |
- **Developed by:** me
|
| 85 |
+
- **Funded by:** me :(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
## Uses
|
| 88 |
|
| 89 |
+
For fun and for limit testing text imprinted on images, commonly found in memes :)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|