Module senticap_reader :: Class SenticapReader
[hide private]
[frames] | no frames]

Class SenticapReader

source code

object --+
         |
        SenticapReader

Handles the reading of the senticap dataset. Has functions to write examples to a simple csv format, and to count the number of examples.

Instance Methods [hide private]
 
__init__(self, filename)
Initializer that reads a senticap json file
source code
`tuple(int, int)`
countExamples(self, train=True, test=True, val=True, pos=True, neg=True)
Count the number of examples matching the filter criteria
source code
 
readJson(self, filename)
Read a senticap json file and load it into `SenticapImage` and `SenticapSentence` classes.
source code
 
writeCSV(self, output_filename, train=True, test=True, val=True, pos=True, neg=True)
Write a CSV file from the examples matching the filter criteria.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]
  images = []
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, filename)
(Constructor)

source code 

Initializer that reads a senticap json file

Parameters:
  • filename - the file path of the json file
Overrides: object.__init__

countExamples(self, train=True, test=True, val=True, pos=True, neg=True)

source code 

Count the number of examples matching the filter criteria

Parameters:
  • train - include training examples
  • test - include testing examples
  • val - include validation examples
  • pos - include positive sentiment examples
  • neg - include negative sentiment examples
Returns: `tuple(int, int)`
a tuple giving the number of images with sentences and the total number of sentences

readJson(self, filename)

source code 

Read a senticap json file and load it into `SenticapImage` and `SenticapSentence` classes. The result is saved in `self.images`.

Parameters:
  • filename - the file path of the json file

writeCSV(self, output_filename, train=True, test=True, val=True, pos=True, neg=True)

source code 

Write a CSV file from the examples matching the filter criteria. The columns of the csv are (filename, is_positive_sentiment, caption). where:

  • filename: is the filename of the MSCOCO image
  • is_positive_sentiment: is 1 if the sentence expresses positive sentiment 0 if the sentence expresses negative sentiment
  • caption: is the tokenized, lowercase, punctuation removed sentence joined with space characters
Parameters:
  • output_filename - path of csv to write
  • test - include testing examples
  • val - include validation examples
  • pos - include positive sentiment examples
  • neg - include negative sentiment examples