I am doing cs224n's assignment.In function test_word2vec, there is some python syntax I don not understand:
""" Interface to the dataset for negative sampling """
dataset = type('dummy', (), {})()
def dummySampleTokenIdx():
return random.randint(0, 4)
def getRandomContext(C):
tokens = ["a", "b", "c", "d", "e"]
return tokens[random.randint(0,4)], \
[tokens[random.randint(0,4)] for i in xrange(2*C)]
dataset.sampleTokenIdx = dummySampleTokenIdx
dataset.getRandomContext = getRandomContext
Question one: What does dataset = type('dummy', (), {})() mean ?
Question two: In dataset.sampleTokenIdx = dummySampleTokenIdx , I do not think dataset has attribute sampleTokenIdx . So, why can dataset invoke it ?