HLR / DomiKnowS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

constraints definition

DariusNafar opened this issue · comments

i want to define some constraints on WIQA data, here are the challenges:
in WIQA we have some paragraphs. for each paragraph, there are some questions and the answer to each question is "more","less" and "no_effect".
the constraints are that some questions are symmetric, therefore must have opposite answers. also some questions are related in a transitive way. like q1->q2, q2->q3, and in these cases if the answer to q1 and q2 is more, q3 must be also more.

one way to define this graph is as follow:

with Graph('QA_graph') as graph:
    paragraph_question = Concept(name='paragraph_question')
    is_more = paragraph_question(name='is_more')
    is_less = paragraph_question(name='is_less')
    no_effect = paragraph_question(name='no_effect')

    nandL(is_more, is_less, no_effect)

    symmetric = Concept(name='symmetric')
    s_arg1,s_arg2=symmetric.has_a(arg1=paragraph_question, arg2=paragraph_question)
    ifL(symmetric, ('x', 'y'), orL( andL(is_more, 'x', is_less, 'y'), andL(is_less, 'x', is_more, 'y')))

    transitive = Concept(name='transitive')
    t_arg1,t_arg2,t_arg3 =transitive.has_a(arg1=paragraph_question, arg2=paragraph_question, arg3=paragraph_question)
    ifL(transitive, ('x', 'y','z'), orL(
       ifL( andL(is_more, 'x', is_more), 'y',is_more, 'z')), 
       ifL( andL(is_more, 'x', is_less, 'y'),is_less, 'z')))
    )

here are the problems with this approach:

  1. is it possible to define the symmetric and transitive sensors like this? given that when we use paragraph_question['text'] in our sensor we won't get a list but each node separately.
  2. given that I won't define any labels on the symmetric and transitive concept and only use them in constraints, will their sensor initialize them? will they be used correctly?
  3. if I do define them with a sensor and don't them, will the system identifies the relation with one_hot list returned by the sensor to the relation property? like this pair[t_arg1.reversed, t_arg2.reversed] = JointSensor(paragraph_question['text'], forward=make_some_pair)

to solve the first challenge in the previous set up I moved to the following graph:

with Graph('QA_graph') as graph:
    paragraph= Concept(name='paragraph')
    question= Concept(name='question')
    para_quest_constain,= paragraph.contains(question)
    is_more = question(name='is_more')
    is_less = question(name='is_less')
    no_effect = question(name='no_effect')

    nandL(is_more, is_less, no_effect)

    symmetric = Concept(name='symmetric')
    s_arg1,s_arg2=symmetric.has_a(arg1=question, arg2=question)
    ifL(symmetric, ('x', 'y'), orL( andL(is_more, 'x', is_less, 'y'), andL(is_less, 'x', is_more, 'y')))

    transitive = Concept(name='transitive')
    t_arg1,t_arg2,t_arg3 =transitive.has_a(arg1=question, arg2=question, arg3=question)
    ifL(transitive, ('x', 'y','z'), orL(
       ifL( andL(is_more, 'x', is_more), 'y',is_more, 'z')), 
       ifL( andL(is_more, 'x', is_less, 'y'),is_less, 'z')))
    )

so now I get a list of questions when I use sensor to define symmetric and transitive Concepts. but the second and third problems still exist, that is would the sensor work without any levels for symmetric and transitive Concepts. also would the program understand the relation just by the first return tensor in one_hot format?


the final method to fix the problem with constraints is as follows:

with Graph('QA_graph') as graph:
    paragraph= Concept(name='paragraph')
    question= Concept(name='question')
    para_quest_constain,= paragraph.contains(question)
    is_more = question(name='is_more')
    is_less = question(name='is_less')
    no_effect = question(name='no_effect')

    nandL(is_more, is_less, no_effect)

    symmetric = Concept(name='symmetric')
    s_arg1,s_arg2=symmetric.has_a(arg1=question, arg2=question)
    ifL(eqL(symmetric, 'label', {1}), ('x', 'y'), orL( andL(is_more, 'x', is_less, 'y'), andL(is_less, 'x', is_more, 'y')))

    transitive = Concept(name='transitive')
    t_arg1,t_arg2,t_arg3 =transitive.has_a(arg1=question, arg2=question, arg3=question)

    ifL(eqL(transitive , 'label', {1}), ('x', 'y','z'), orL(
       ifL( andL(is_more, 'x', is_more), 'y',is_more, 'z')), 
       ifL( andL(is_more, 'x', is_less, 'y'),is_less, 'z')))
    )

in this case, we define pair relation between all questions of a paragraph but also define a label and set it to one only for the pair we actually want.
would this solve the second and third challenge?

@AdmiralDarius close this if this is resolved.