HLR / DomiKnowS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

questions about doc

DariusNafar opened this issue · comments

hey there,

these are my first questions about the doc. I appreciate it if you answer them thoroughly. some questions have overlapping parts but please answer them for each section separately. also if some of my questions are answered in docs and I missed it, indulge me and answer them again.

sensors:

  1. in this code
(rel_sentence_contains_word,) = sentence.contains(word)
rel_sentence_contains_word['forward'] = TokenizerEdgeSensor('index', mode='forward', to=('index', 'ids', 'offset'), tokenizer=Tokenizer())

this is the first way of initializing a contains edge out of three( there are three ways right? )
is the first arg "index" the property of the father node or the first node in the graph? ( if it's the first node how to address other nodes?).
Should I add all the properties of the father node that I want to use before mode?
can I remove the father's property after tokenizing? ( like with detach)
what is the mode arg and what are other "forward" alternatives? (please explain with examples)
This method of initializing is only for contains? or it has other uses?
how does the code work with the arity of the relation? does it only work with 1 to many relations?
what is the tokenizer input and outputs? is it a list of sents? in what format and so on. ( transformers tokenizer's input is very versatile so explain the input and output precisely)

  1. predefined sensors link in docs doesn't work.
  2. what are the readersensors data conversion types? ( so for instance it changes the list to torch tensor. right?) please explain for every input of list ( 1 dim, 2 dim and ...), str, int, ...
    ** do the data conversion changes if label=True?**
  3. in this code
def offset_len(offset):
  return offset[:,1] - offset[:,0]
word['len'] = FunctionalSensor('offset', forward=offset_len)

functional sensor forward gets a list of word len? and it returns a list? is the input and out python lists ( as opposed to torch tensor or NumPy array)?

  1. in this code from pipeline:
word[people] = ReaderSensor(keyword='people', label=True)
word[organization] = ReaderSensor(keyword='organization', label=True)
pair[work_for] = ReaderSensor(keyword='work_for', label=True)

how does the word[people] readersensor work? in the example/demo the input is a python array of 1s and 0s . so how does the code know not to assign the entire list to one word( and assign one element to each word)? is it because the word is not the main node? what if we give the input in other ways like [[1,0],[1,0],[0,1],[1,0]...]? does the label=True change the processing dynamic?

what happens if there is a mismatch between our tokenizer and labels? ( like creating more tokens than intended? )
how do the pair[work_for] readersensor work here? what is the input data and how does the sensor process them?

  1. in the 5th question's code:
    I noticed there are two notations of using is_a concepts
    for example for word and it's subtypes of people and organization we can use it as:
    word[people]= readersensor... or people['label']=readersensor...

are these two notations equal? if I want to use the second notation, how can I use the readersensor?
does the logical constraints apply in both notations? ( like disjoint(people,organization) )

  1. in this code in the pipeline:
    pair[wor_for] = ModuleLearner('emb', module=torch.nn.Linear(768*2, 2))
    how do pair[wor_for] has an emb property? and why is it a subtype of the word?
    is there any way to get the shape and type of properties? it is really necessary as it is a common thing to need to change the tensor sizes in PyTorch.

  2. in the sensor part of the docs, how can one override the forward function of the sensor? please give some examples for both cases of using a context and a datanodebuilder. ( that uses the input args of forward and other methods in sensor)
    also, explain how the datanodebuilder navigates through the sensor.
    is the context just a single dict? or a list of dicts here?

**I didn't quite understand what a torch sensor is. so please explain what is the difference between a torch sensor and other non-torch sensors. also, what are pres and input args and property exactly? what are their dimensions and how does it change ( please explain with examples). also, what is the pres and input dynamic? ( how do they work with each other?)

  1. this may be related more to graphs but I will have it in the sensor section of questions:
    What are the Concept property and attributes? ( please also explain all the methods of it with their inputs and outputs precisely)

what are the Relationproperty and attributes? ( please also explain all the methods of it with their inputs and outputs precisely). please also explain how to use the Relation class directly and its equivalent ways of defining it. ( please do explain this part even if I don't need to use the Relation class directly)

  1. in this code:
    sentence.contains()[word]=simpleTokenizerSensor('raw')
    what is the contains() method? what are its inputs and outputs exactly? ( please explain it even if this notation is deprecated)
    is contains used only for contains relation or general relations?

please explain inputs and outputs of simpleTokenizerSensor( if it's a real sensor and not just a filler)

  1. in the demo example code:
    scw=sentence.relate_to(word)[0]
    what is the relate_to method? please completely explain it's inputs and outputs.
    is scw a relation class? and is it equivalent to (rel,)=sentains.contains(word) ? is it equivalent to sentence.contains()[word]?

it's also used here so please explain it here as well:
a1,a2=pair.relate_to(word)
what are the differences between relate_to and contains methods of Concept?

in the following line of code:
word[scw,'text']=JointSensor(sentence['text'],forward=tokenize)
this is the third way to tokenizing that i saw.
does it only work for contains?
what is the exact notation of using this? should I put the relation property first? can it only take one relation property?

12.in this code in the demo example:
arg1, arg2 = pair.relate_to(word) pair[arg1.reversed, arg2.reversed] = JointSensor(word['text'], forward=make_pair) pair['emb'] = FunctionalSensor(arg1.reversed('emb'), arg2.reversed('emb'), forward=concat) pair[work_for] = ModuleLearner('emb', module=Classifier(200))

what are the types of arg1 and arg2? please explain all their properties? what are the reversed property and its type?
also please explain the next three lines of code in a documentary fashion. like explaining the inputs and outputs of the classes used. ( including the forward's inputs and outputs)

13.what is the difference between readersensor and labelreadersensor? and why in some examples they get the reader as input?

  1. please explain the inputs and outputs of the following sensors and their uses precisely ( also their properties and methods):
  • TorchSensor
  • DataSensor
  • LabelSensor
  • FunctionalSensor
  • CartesianSensor
  • NorminalSensor
  • SpacyTokenizorSensor
  • BertTokenizorSensor
  • BertEmbeddingSensor
  • ConstantSensor
  • PrefilledSensor
  • TriggerPrefilledSensor
  • JointSensor
  • ReaderSensor
  • FunctionalReaderSensor
  • LabelReaderSensor
  • NominalSensor
  • ModuleSensor
  • TorchEdgeSensor
  • AggregationSensor
  • MaxAggregationSensor
  • MinAggregationSensor
  • MeanAggregationSensor
  • ConcatAggregationSensor
  • LastAggregationSensor
  • FirstAggregationSensor
  • ConcatSensor
  • ListConcator

hey there,

these are my first questions about the doc. I appreciate it if you answer them thoroughly. some questions have overlapping parts but please answer them for each section separately. also if some of my questions are answered in docs and I missed it, indulge me and answer them again.

sensors:

  1. in this code
(rel_sentence_contains_word,) = sentence.contains(word)
rel_sentence_contains_word['forward'] = TokenizerEdgeSensor('index', mode='forward', to=('index', 'ids', 'offset'), tokenizer=Tokenizer())

this is the first way of initializing a contains edge out of three( there are three ways right? )
is the first arg "index" the property of the father node or the first node in the graph? ( if it's the first node how to address other nodes?).
Should I add all the properties of the father node that I want to use before mode?
can I remove the father's property after tokenizing? ( like with detach)
what is the mode arg and what are other "forward" alternatives? (please explain with examples)
This method of initializing is only for contains? or it has other uses?
how does the code work with the arity of the relation? does it only work with 1 to many relations?
what is the tokenizer input and outputs? is it a list of sents? in what format and so on. ( transformers tokenizer's input is very versatile so explain the input and output precisely)

To check on the semantic of sensors and Edgesensors please look at the following issue:
Issue #213

  1. predefined sensors link in docs doesn't work.
    I believe we do not have a proper page for the predefined sensors yet. Feel free to add information on this part.
  2. what are the readersensors data conversion types? ( so for instance it changes the list to torch tensor. right?) please explain for every input of list ( 1 dim, 2 dim and ...), str, int, ...
    ** do the data conversion changes if label=True?**

ReaderSensor prints out the exact keyword read from the dictionary with whatever type as output. Initially, the label was used to change the type of the output but I think it is now used for internal mention of something being annotated rather than predicted. @guoquan can elaborate more on if the data type is also still being changed.

  1. in this code
def offset_len(offset):
  return offset[:,1] - offset[:,0]
word['len'] = FunctionalSensor('offset', forward=offset_len)

functional sensor forward gets a list of word len? and it returns a list? is the input and out python lists ( as opposed to torch tensor or NumPy array)?

The output of the forward function can have any structure~(as far as being compatible with a subscribable variable) and following the discussion in #213, the first dimension of the input will always be the number of instances.

  1. in this code from pipeline:
word[people] = ReaderSensor(keyword='people', label=True)
word[organization] = ReaderSensor(keyword='organization', label=True)
pair[work_for] = ReaderSensor(keyword='work_for', label=True)

how does the word[people] readersensor work? in the example/demo the input is a python array of 1s and 0s . so how does the code know not to assign the entire list to one word( and assign one element to each word)? is it because the word is not the main node? what if we give the input in other ways like [[1,0],[1,0],[0,1],[1,0]...]? does the label=True change the processing dynamic?

No matter the internal shape of the output, the first dimension is always the number of instances and the rest are the features.

what happens if there is a mismatch between our tokenizer and labels? ( like creating more tokens than intended? )

@auszok can answer this, it is either adding instances or giving error because of the feature being mismatched to the existing indexes. The second scenario is probably expected.

how do the pair[work_for] readersensor work here? what is the input data and how does the sensor process them?

This is just another reader sensor, the ReaderSensor outputs whatever keyword it reads from the dictionary.

  1. in the 5th question's code:
    I noticed there are two notations of using is_a concepts
    for example for word and it's subtypes of people and organization we can use it as:
    word[people]= readersensor... or people['label']=readersensor...

People['label'] is a deprecated method of the framework, We now use predictions as properties of their main concept.

are these two notations equal? if I want to use the second notation, how can I use the readersensor?
does the logical constraints apply in both notations? ( like disjoint(people,organization) )

  1. in this code in the pipeline:
    pair[wor_for] = ModuleLearner('emb', module=torch.nn.Linear(768*2, 2))
    how do pair[wor_for] has an emb property? and why is it a subtype of the word?

Whatever property being used should have already been defined in another sensor. The code may only represent a portion of the modeling related to the reader and the execution is not in the same order as you write the code. You can consider that more like functional programming rather than procedural. Pair is also not a subtype of the word.

is there any way to get the shape and type of properties? it is really necessary as it is a common thing to need to change the tensor sizes in PyTorch.

As a common practice, people tend to design a general Config file to be shared among all their learners and modules, you can use the same here to track the size.

  1. in the sensor part of the docs, how can one override the forward function of the sensor? please give some examples for both cases of using a context and a datanodebuilder. ( that uses the input args of forward and other methods in sensor)
    also, explain how the datanodebuilder navigates through the sensor.
    is the context just a single dict? or a list of dicts here?

In every sensor, you can either inherit from the main sensor class and change the internal functions as you wish. You can also just pass a function to the init function of each sensor with the key "forward" and customize that function. The forward function receives a list of inputs defined as *pres in the sensor initialization.

**I didn't quite understand what a torch sensor is. so please explain what is the difference between a torch sensor and other non-torch sensors. also, what are pres and input args and property exactly? what are their dimensions and how does it change ( please explain with examples). also, what is the pres and input dynamic? ( how do they work with each other?)

The framework was initially designed by sensors extended for AllenNLP and then customized to be compatible with Torch. The basic class of TorchSensor is to create a branch of sensors that rely on tensor operations. For now, this is usually the base sensor for all of the framework sensors.

  1. this may be related more to graphs but I will have it in the sensor section of questions:
    What are the Concept property and attributes? ( please also explain all the methods of it with their inputs and outputs precisely)

To get all the methods, you have to look at the code as we do not have a detailed API doc for now. Besides, I do not understand what you mean by the concept, property and attributes. Do you mean the Concept class and its attributes or what we call attributes in the Declarative Learning program on our graph.

  1. in this code:
    sentence.contains()[word]=simpleTokenizerSensor('raw')
    what is the contains() method? what are its inputs and outputs exactly? ( please explain it even if this notation is deprecated)
    is contains used only for contains relation or general relations?

contains is a relationship used when an entity is a part of another entity indicating a "one to many" relationship from parent to child.

please explain inputs and outputs of simpleTokenizerSensor( if it's a real sensor and not just a filler)

  1. in the demo example code:
    scw=sentence.relate_to(word)[0]
    what is the relate_to method? please completely explain it's inputs and outputs.

The relate_to function is a method implemented in concept to retrieve the relation properties as defined in the graph. The input would be another concept that you are interested in to check if there is a relation and if yes, retrieve it. The output is always a list of the relationships existing between the concept and the input.

is scw a relation class? and is it equivalent to (rel,)=sentains.contains(word) ? is it equivalent to sentence.contains()[word]?

I am not sure what the "sentence.contains()[word]" notation is, @guoquan can probably elaborate more.
The scw variable is an instance of relation class as is indeed equivalent to rel from your second expression.

it's also used here so please explain it here as well:
a1,a2=pair.relate_to(word)
what are the differences between relate_to and contains methods of Concept?

in the following line of code:
word[scw,'text']=JointSensor(sentence['text'],forward=tokenize)
this is the third way to tokenizing that i saw.

This is probably the only valid approach currently being used.

does it only work for contains?

It is a general sensor that outputs multiple values in a tuple and is divided into their proper properties at the internal level of storing the data. There is nothing special about any of the sensors themselves to only work on a certain criterion.

what is the exact notation of using this? should I put the relation property first? can it only take one relation property?

The relation property is used whenever you tend to connect two concepts to each other, which is used to make links on the data level. I believe it doesn't matter which property you put first here. I may be wrong about it @guoquan. But what actually matters, is to store that property before other properties on the same concept as it is used to initialize the instances.

12.in this code in the demo example:
arg1, arg2 = pair.relate_to(word) pair[arg1.reversed, arg2.reversed] = JointSensor(word['text'], forward=make_pair) pair['emb'] = FunctionalSensor(arg1.reversed('emb'), arg2.reversed('emb'), forward=concat) pair[work_for] = ModuleLearner('emb', module=Classifier(200))

what are the types of arg1 and arg2? please explain all their properties? what are the reversed property and its type?

arg1 and arg2 are relation classes. The reversed property of a relation is the same relation in which its source and target is flipped and is an instance of the same class.

also please explain the next three lines of code in a documentary fashion. like explaining the inputs and outputs of the classes used. ( including the forward's inputs and outputs)

13.what is the difference between readersensor and labelreadersensor? and why in some examples they get the reader as input?

  1. please explain the inputs and outputs of the following sensors and their uses precisely ( also their properties and methods):
  • TorchSensor
  • DataSensor
  • LabelSensor
  • FunctionalSensor
  • CartesianSensor
  • NorminalSensor
  • SpacyTokenizorSensor
  • BertTokenizorSensor
  • BertEmbeddingSensor
  • ConstantSensor
  • PrefilledSensor
  • TriggerPrefilledSensor
  • JointSensor
  • ReaderSensor
  • FunctionalReaderSensor
  • LabelReaderSensor
  • NominalSensor
  • ModuleSensor
  • TorchEdgeSensor
  • AggregationSensor
  • MaxAggregationSensor
  • MinAggregationSensor
  • MeanAggregationSensor
  • ConcatAggregationSensor
  • LastAggregationSensor
  • FirstAggregationSensor
  • ConcatSensor
  • ListConcator

Please refer to the API docs to see the input, output of some of these sensors. Feel free to add any additional documentation as we move forward with finalizing the new interface and the document.

2. what are the readersensors data conversion types? ( so for instance it changes the list to torch tensor. right?) please explain for every input of list ( 1 dim, 2 dim and ...), str, int, ...
** do the data conversion changes if label=True?**

ReaderSensor prints out the exact keyword read from the dictionary with whatever type as output. Initially, the label was used to change the type of the output but I think it is now used for internal mention of something being annotated rather than predicted. @guoquan can elaborate more on if the data type is also still being changed.

In ReaderSensor, the only conversion is that I will try to convert anything it read into a torch tensor. If the conversion fails, the value is provided as it is read from the reader.

is scw a relation class? and is it equivalent to (rel,)=sentains.contains(word) ? is it equivalent to sentence.contains()[word]?

I am not sure what the "sentence.contains()[word]" notation is, @guoquan can probably elaborate more.

I checked back the example of "sentence.contains()[word]" and it seems it is not supported now. The original example means something like rel_sentence_contains_word[word] = SomeTorchEdgeSensor(). But edges don't work in that way now.