Spaces:
Sleeping
Sleeping
Download utils/text_utils.py from PRUTHVIn/vqa_project: direct link, hf CLI and curl.
- Browser
- Download file 305 Bytes
-
https://huggingface.co/spaces/PRUTHVIn/vqa_project/resolve/main/utils/text_utils.py
- Command line
-
hf download hf://spaces/PRUTHVIn/vqa_project/utils/text_utils.py
-
curl -L -o text_utils.py https://huggingface.co/spaces/PRUTHVIn/vqa_project/resolve/main/utils/text_utils.py
305 Bytes
| import re | |
| def clean_text(text): | |
| text = text.lower() | |
| return re.sub(r"[^a-z0-9 ]", "", text) | |
| def encode_question(q, vocab, max_len=20): | |
| tokens = q.split() | |
| enc = [vocab.get(w, vocab["<UNK>"]) for w in tokens] | |
| enc = enc[:max_len] + [vocab["<PAD>"]] * (max_len - len(enc)) | |
| return enc | |