Search code examples
pythonhuggingface-transformersbbc-microbit

How to add a module (Transfomers) to the microbit code interface?


So, I was making a program on the BBC microbit that would change its face according to the gestures you made with it. Then I looked into to adding a chat bot built in to it and it would talk back to you with the speech function. I then saw a bit about DialoGPT and I looked into it and saw that it required the transformers library. Then I did some digging on how to add third party libraries into the microbit Py interface and found this help and support article and it said all you had to do was "drag and drop" the file into the web page. I then went, and downloaded the library via pip in the terminal and found that library in my files, uploaded it to google drive (because I needed to get the file to another computer for reasons I wont get into. I also couldn't download libraries on the other computer) the waited for it to upload, downloaded it on the other computer and did what the article said. (this is where I think I went wrong) expect it wouldn't let me upload folders and I just dragged each individual file in. then after all of this, I tried importing the modules I needed but it still said that they were not modules in the code. if anybody knows how to do this or just using a different model or just having to scrap the chat bot idea in general, let me know.


Solution

  • The micro:bit has an embedded microprocessor with less than 1 MB of storage in total. The HuggingFace transformers library is nearly 8 MB on its own, then to use it you need to download models that can be gigabytes in size.

    The comment by @jasonharper is correct: it's not that you're going about it the wrong way, it's simply not possible to run this library on the micro:bit (and even if you could fit the library and model on it, and dealt with any incompatibilities between 'full' Python and the micro:bit's MicroPython language, it would probably be unusably slow). That's just not the kind of thing the microbit is designed to be capable of.

    It might be possible to program the micro:bit to record your voice and transmit the recording to a PC running the speech-to-text, chatbot, and text-to-speech functions, which would then transmit the response back to the micro:bit to play back to you. I would say the PC side of that is a significant project if you're not very familiar with the technologies involved, though.