I wrote some starter code to generate a CSV file that can be imported directly into Anki to create a deck based on the notebook that’s being created in out study group.
This code through the notebook and for every Level 3 header or below attempts to create a new card. The card front will be the code examples contained in the section. The card back will be the header of the section saying what the symbol is, and all the code output/answers. The goal is to remember both the symbol names AND what they do. For example one card looks like this:
Card Front:
Card Back:
Things that could be improved/done differently:
Maybe this could be run through CI as something to be kept up to date and available as part of the apl-study repo
Handle the exception when there is no code output. Probably several other code improvements could be made by studying nbprocess and seeing how they deal with notebooks.
Could consider creating a separate card for each code example, instead of 1 card for each section.
Could try to optimize formatting to make cards more aesthetically pleasing
There is another import format that’s not csv. Is that feasible to use and more flexible?
Could try writing it in APL
If I end up using Anki a bunch I will put more time into it, but for now it’s good enough for me. I want to try using Anki for a while so I have a better idea of what would be helpful before I do too much and this gets me started. If anyone improves on this please share here for everyone to benefit!
import json
import pandas as pd
nb = json.load(open('APL.ipynb'))
front = ''
back = ''
cards = []
for cell in nb['cells']:
if (cell['cell_type'] == 'markdown') and ('###' in ''.join(cell['source'])):
if front != '': cards.append(pd.DataFrame([[front,back]]))
back = '<br/>'.join(cell['source']) + '<br/>'
front = ''
elif cell['cell_type'] == 'code':
front = front + '<br/>'.join(cell['source']) + '<br/>'
try:
back = back + '<br/>'.join(cell['outputs'][0]['data']['text/html']) + '<br/>'
except:
pass
pd.concat(cards).to_csv('deck.csv',index=False,header=False)
A suggestion: Piotr Wozniak recommends the each card has a minimal single question. So that would suggest each card should just have a single input/output pair, rather than all of them.
(I can see some benefits of doing them all at once for a function in a single card too though – just passing along this thought in case it’s helpful.)
That’s good to know - I will make that change later today and update the code above. The other thing I was considering is which direction to go for glyph names. (ie Remember english name from glyph vs remember glyph from english name).
Maybe I should have a card for both? I need to read up on this!
Also: I am thinking I will maintain a copy of the APL notebook that has a couple of additions that will let me generate a couple more cards automatically:
Includes key shortcut
Includes a plain english simple as possible description of what it is.
Is this something that you would want added to the notebook your are creating, or should I do that separately?
There are a few drawbacks in that the code cell generates the card so code cells must be self contained. If a variable that is used is defined in previous cells, the card will not show that variable Not sure about how to fix this in a clean way other than writing the notebook with that in mind.
Possible Nbprocess Extension
I also think it would be cool for this to be an nbprocess extension for courses/educational blogs/books (either as part of nbprocess or as a seperate extension) that I might toy with (though I might not, so if inspiration hits anyone go for it). The idea would be this:
Have an Anki flag that turns any code cell into an Anki card (code = front, output = back).
Each notebook (article/chapter/post/w.e) has the example code, problems, or homework flagged with the Anki Flag
Anki importable csv file is automatically built from the notebooks via the flag
@Ezno , I imported the deck.
Tried to Study it and got:
**Congratulations! You have finished this deck for now.**
If you wish to study outside of the regular schedule, you can use the <U+2068>custom study<U+2069> feature.'
I have noticed that the import immediately says “successful”, but it does take about 30 seconds to complete AFTER it says the import is complete. Can you try again and wait a minute before going into study?
Can you click into view the deck - do you see the cards there?
Thank you so much for creating this tool @Ezno , I was able to generate and load the file into my local Anki app, but on macOS, it seems there are spaces between the bounding box characters? Could this be a problem with the font I’m using on the MacOS ?
I’m not sure what you mean - What is different between this and what you see in jupyter?
The font used is SAX2. You could try downloading the font on your computer and then installing it (I think on mac you can just double click it) to get the font used on our apl-study website to see if that improves things.
No problem! I made it for myself first and foremost, and I am glad it’s useful to others as well.
Keep in mind that some of the cards will be broken due to the limitation I mentioned above. Any code cell that is not self contained won’t make sense (ie variable assigned in one cell and test in another).
If enough people find it useful maybe we can come up with a way to address that.
Alright all - I went much further down this rabbit hole than intended…
I just pushed another anki deck as an experiment. This deck is a complete “vocabulary” deck. While the previous deck builds from a jupyter notebook and has great code examples, this one is vocabulary and glyph recognition scraped direct from the dyalog documentation pages. Links are the bottom of this post.
This deck:
Should contains all Glyphs (Scrapes the APL documentation website for it)
Cards have every combination I could think of going between various names, symbol, and documentation.
Contains hyperlink on the back of cards to relevent doc pages
Examples
There are a lot of different type of cards, but here’s a few examples. Possibly too many cards, so I may modify this over time as I use the app and see what I need. Feel free to take the code and run it yourself and comment out any cards.append line you don’t want!
Wow this is amazing! coincidentally, I was creating physical flashcards last night just for the glyphs as I feel like it’s something I need to get a handle on, so this will be immensely helpful to me! Thanks so much!
I’m just going through these and while I’m at it, I should report some things that I see. I noticed that some of the entries appear twice? I’m not sure why this might be but if I do:
grep ^⌺ apl-docs-anki.csv
or
grep ^⍤ apl-docs-anki.csv
I see two instances of it . I won’t copy the output but it’s easy to see.