Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Multi-output model #92

Closed
Qian16 opened this issue May 20, 2019 · 19 comments
Closed

[Question] Multi-output model #92

Qian16 opened this issue May 20, 2019 · 19 comments
Assignees
Labels
question Further information is requested

Comments

@Qian16
Copy link

Qian16 commented May 20, 2019

Hello Dear @BrikerMan. Thanks for creating this good library. However, I want to perform multi-outputs classification(This is different to multi-label).
My input is sentence and the outputs are two full-connected networks where each one has its own labels (One input-->Two branch networks).

I want to know if Kashgari supports multi-outputs classification.

input_text=[['This','news',are',very','well','organized'],
['What','extremely','usefull','tv','show'],
['The','tv','presenter','were','very','well','dress']]

label_list1=[1,0,1]
label_list2=[1,1,0]

xdata=input_text
ydata=[label_list1,label_list2] #In Keras, for multi-output we make a list of both labels.
model.fit(xdata,ydata,epochs=1)

Thank you.

@Qian16 Qian16 added the question Further information is requested label May 20, 2019
@BrikerMan
Copy link
Owner

Yes, kashgari support multi-label classifacation.

input_text = [
   ['This','news',are',very','well','organized'],
   ['What','extremely','usefull','tv','show'],
   ['The','tv','presenter','were','very','well','dress']
]

labels = [
   ['class1', 'class3'],
   ['class1', 'class2'],
   ['class1', 'class2', 'class3'],
]

model.fit(input_text, labels, multi_label=True)

@Qian16
Copy link
Author

Qian16 commented May 20, 2019

Dear @BrikerMan, thank you for your answer. I am little confused about how you transform the labels.

Actually, they dataset with tokenized text input looks like this:

  input_text                                                             |  label1  | label2
  1. ['This','news',are',very','well','organized'] | 1 | 1
  2. ['What','extremely','usefull','tv','show'] | 0 | 1
  3. ['The','tv','presenter','were','very','well','dress'] | 1 | 0

So, i can't figure out how those 'class1','class2' and 'class3' are mapped.
Thank you.

@alexwwang
Copy link
Collaborator

alexwwang commented May 20, 2019 via email

@BrikerMan
Copy link
Owner

Just keep the label that should be output as 1.

x: ['This','news',are',very','well','organized'] y:  [lavel1 , label2]
x: ['What','extremely','usefull','tv','show'] y:  [label2]
x: ['The','tv','presenter','were','very','well','dress'] y:  [label1]

@Qian16
Copy link
Author

Qian16 commented May 20, 2019

@alexwwang @BrikerMan Thank you. It will be nice to have Kash that supports all features. Big up guys.

@BrikerMan
Copy link
Owner

@Qian16 I got it wrong, Kashgari support multi-label classification. Not support the multi-output classification.

@alexwwang
Copy link
Collaborator

@BrikerMan By modifying method get_data_generator in classification base class, we could support multi-output classification. Users could define or assemble models themselves simply under Kash structure.

@Qian16
Copy link
Author

Qian16 commented May 21, 2019

@alexwwang Thank you. Can you show me the test you did(or tel me the exact line to change)? To define a model and assemble it to Kash i did. Thank you.

@BrikerMan
Copy link
Owner

get_data_generator

I am working on it. I will submit the demo later today.

@Qian16
Copy link
Author

Qian16 commented May 21, 2019

@alexwwang Wow! Thank you for saving my life!!!

@alexwwang
Copy link
Collaborator

@BrikerMan @Qian16 The main change need to be done is the processing of label or y data. Just like what have been done with x data in multi-input scenario, the y part also need an automatic de-nest from input list and re-nest when assemble to batch later.

It's not too hard, I think.

@alexwwang
Copy link
Collaborator

@alexwwang Wow! Thank you for saving my life!!!

It's an honor of @BrikerMan. He'll implement the last mile. :)

@BrikerMan
Copy link
Owner

@alexwwang @Qian16 I have added an example of a multi-output model. Check it out. Remember u need to run the tf.keras-version branch, and it is an early stage of development, may have lots of bugs.

@Qian16
Copy link
Author

Qian16 commented May 22, 2019

@BrikerMan @alexwwang Thank you for great job. It working correctly.

@Qian16
Copy link
Author

Qian16 commented May 22, 2019

@BrikerMan Did you try to use BERTEmbedding ?

@BrikerMan
Copy link
Owner

Not yet, but it should work fine. Remember to pull the latest code.

@Qian16
Copy link
Author

Qian16 commented May 23, 2019

@BrikerMan to run BERT, we need to change in keras fit() function
#Build batch logs
if isinstance(x,tuple):
batch_size=x[0].shape[0]

Thanks.

@BrikerMan
Copy link
Owner

@BrikerMan to run BERT, we need to change in keras fit() function
#Build batch logs
if isinstance(x,tuple):
batch_size=x[0].shape[0]

Thanks.

Fixed, Added new test case at b27dea0 .

@Qian16
Copy link
Author

Qian16 commented May 30, 2019

The accuracy achieved by multi-output model is not poor! The performance of individual models is very good compared to multi-output. May be we need to check it again. Thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants