Skip to content

Instantly share code, notes, and snippets.

@YugeTen
Created May 25, 2019 13:34
Show Gist options
  • Save YugeTen/d442305b769344ba8db9ac221f11cc4b to your computer and use it in GitHub Desktop.
Save YugeTen/d442305b769344ba8db9ac221f11cc4b to your computer and use it in GitHub Desktop.

Prerequisite: gensim.

Two scripts under src/ that you need to look at:

  1. generate_embeddings.py: Creates dataloaders for embedded sentences using fasttext model trained on CUB dictionary. The train_loader and test_loader will return dataB of length 2: dataB[0]: [batch_size, sentence_length, embedding_vector_size] dataB[1]: [batch_size], original sentence length before truncation or padding (you can probably ignore this one, but I kept it there just in case you need the original length to truncate the sentence when calculating correlations)

  2. coherence.py: this one is pretty much ready to go, it is defaulted to load the trained cub model under expeirments/ft_obj. You just need to import the CCA module (see usage in line 65, 66 and 77) that can be called with:

coherence = CCA(images, sentences)

Where images is of shape [batch_size, feature_size] and sentences [batch_size, sentence_length, embedding_vector_size].

@YugeTen
Copy link
Author

YugeTen commented May 25, 2019

The image features generated with resnet101 are data/cub/resnet101_2048/train.ft and data/cub/resnet101_2048/test.ft, their corresponding raw data (arranged in the same order) are in data/cub/resnet101_2048/train.data and data/cub/resnet101_2048/test.data.
These can be loaded with torch.load command.

@YugeTen
Copy link
Author

YugeTen commented May 25, 2019

The image features generated with resnet101 are data/cub/resnet101_2048/train.ft and data/cub/resnet101_2048/test.ft, their corresponding raw data (arranged in the same order) are in data/cub/resnet101_2048/train.data and data/cub/resnet101_2048/test.data.
These can be loaded with torch.load command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment