modAL-python / modAL

A modular active learning framework for Python
https://modAL-python.github.io/
MIT License
2.21k stars 324 forks source link

Active learner in Dash #75

Open sarahdc1998 opened 4 years ago

sarahdc1998 commented 4 years ago

Hi,

I would like to use modAl in Dash. The problem is, global variables will break the Dash app. That's why they invented the Dash Store component. In the first callback, the active learner will be created. But if I want to interactive labeling, a second callback will be needed. Through the Store object, the learner will be passed to the second callback. Now, the active learner object will need to be in JSON format.

Does someone has experience with this?

Thanks in advance, Sarah

renanj commented 4 years ago

I also want to use the Dash with modAl for a project.

Sarah, do you have an app.py example to share? If is a simple (toy example) is better.

Em qui, 5 de mar de 2020 às 10:53, sarahdc1998 notifications@github.com escreveu:

Hi,

I would like to use modAl in Dash. The problem is, global variables will break the Dash app. That's why they invented the Dash Store component. In the first callback, the active learner will be created. But if I want to interactive labeling, a second callback will be needed. Through the Store object, the learner will be passed to the second callback. Now, the active learner object will need to be in JSON format.

Does someone has experience with this?

Thanks in advance, Sarah

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/modAL-python/modAL/issues/75?email_source=notifications&email_token=ACSR3VVAS2WWH6QFPW5O7A3RF6VHHA5CNFSM4LCKLSFKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4ISZFXWA, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACSR3VXMJWGYU5SZFUOX76TRF6VHHANCNFSM4LCKLSFA .

cosmic-cortex commented 4 years ago

Hi!

Unfortunately, I have zero experience with Dash and I haven't thought about JSON serialization of modAL objects. Serialization is possible in my opinion. What kind of machine learning model do you use?

What I would do in this case is to save the model file to disk and use an object similar to this:

{
"model_path": "/path/to/model"
"X_training": ... # serialized numpy array
"y_training": ... # serialized numpy array
"query": "modAL.uncertainty.uncertainty_sampling"
}

and then rebuild the learner with a custom function. However, you have to take this with a grain of salt since I have never done anything like this before :)

If you could post some example code (if it is public), I might be able to help more with this once I understand the details.

cosmic-cortex commented 4 years ago

After thinking about this a while, another soultion, and I believe this is the proper one, is not to serialize the model and pass it around, but set up a microservice with FastAPI + Docker to serve the model and just call the appropriate API endpoints from the Dash app.

If you are interested in this solution, I have an example project achieving a similar result in this repository: https://github.com/cosmic-cortex/fastAPI-ML-quickstart. You can find the corresponding tutorial post here: https://towardsdatascience.com/how-to-properly-ship-and-deploy-your-machine-learning-model-8a8664b763c4?source=friends_link&sk=0a570536506814535471f83357655b75