<jupyter_start><jupyter_text>Parameters<jupyter_code>model = '../models/flickr8k/BEST_checkpoint_bs80_ad300_dd300_elr0.0_dlr0.0004.pth.tar'
img_path = '../data/datasets/flickr8k/img/3758787457_1a903ee1e9.jpg'
word_map_path = '../data/datasets/flickr8k/WORDMAP_flickr8k.json'
smooth = True
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")<jupyter_output><empty_output><jupyter_text>Load model<jupyter_code>checkpoint = torch.load(model, map_location=str(device))
decoder = checkpoint['decoder']
decoder = decoder.to(device)
decoder.eval()
encoder = checkpoint['encoder']
encoder = encoder.to(device)
encoder.eval()<jupyter_output><empty_output><jupyter_text>Load word map, create inverse word map<jupyter_code>with open(word_map_path, 'r') as j:
    word_map = json.load(j)
rev_word_map = {v: k for k, v in word_map.items()}<jupyter_output><empty_output><jupyter_text>Encode, decode with attention and beam search<jupyter_code>seq, alphas = caption_image_beam_search(encoder, decoder, img_path, word_map, 1)
alphas = torch.FloatTensor(alphas)<jupyter_output>/home/pabvald/.local/share/virtualenvs/instagram-caption-generator-Z18861q1/lib/python3.8/site-packages/torch/nn/functional.py:718: UserWarning: Named tensors and all their associated APIs are an experimental feature and subject to change. Please do not use them for anything important until they are released as stable. (Triggered internally at  /pytorch/c10/core/TensorImpl.h:1156.)
  return torch.max_pool2d(input, kernel_size, stride, padding, dilation, ceil_mode)<jupyter_text>Visualize caption and attention of best sequence<jupyter_code>visualize_att(img_path, seq, alphas, rev_word_map, smooth)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1152046783625731, 'fraction_numerical': 0.031578947368421054, 'mean_word_length': 7.729591836734694, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '4867', 'license': 'MIT', 'n_tokens_mistral': 651, 'n_tokens_neox': 604, 'n_words': 112, 'path': 'notebooks/visualize_results.ipynb', 'repo_name': 'pabvald/instagram-caption-generator', 'size': '1710'}