Sunday, September 23, 2018

Moving your playlists from Spotify to Google music

Want to move from Spotify to Google music without loosing your playlists. At the link below there are som scripts that move your playlists from Spotify to Google music.

https://gitlab.com/Pytt/csv_playlist

Saturday, June 16, 2018

Transaction Viewer

I thought it would be interesting to see where my money is going. How much money am I spending on eating out, petrol, clothes, etc. There are a number of services that can do that but they either required too much manual work or they wanted full access to your bank accounts, so I decided to write a small python script myself.

The script loads the account history, which in my case (SEB) comes in an excel-file, and displays the  information in two stacked area charts.


The top one shows incomes over time, in my example data there is only one income, the light blue area. The bottom chart shows expenses over time. You can pan and zoom in the chart, and when hovering over an area details are shown. If you load multiple files at once the script will merge them and remove transactions between the accounts.

You can rename areas by right-clicking them. If you rename two areas to the same name they will be merged. Below I have renamed both "Shell" (pink) and "BP" (light blue/gray) to "Petrol" (light violet). If you rename an area to nothing it will be removed.


Some payments are sporadic, like the green and blue ones, and they kind of screw up the chart if you just want to get an overview of where money is going. To fix this I implemented smoothing. Below is the same chart but with a 12 month sliding average.


The source can be downloaded here.

Monday, January 1, 2018

Character prediction with a LSTM-network

I just bought a new graphics card, which gives me the ability to train much larger networks. To try it out I thought I would create one of those cool networks that can generate real looking text.

To generate text you use a network that can predict the next character in a stream of characters. The network outputs a probability for each possible next character, 128 probabilities for ASCII text. If you input "cat" the network might give a 40% likelihood of the next character being a space, 20% that the next character is "s" (to create "cats"), and 0.001% that next character is "\". Using the probabilities the network produced you append the stream with a random character and then you re-run it all. By repeating this process a random text of any length can be produced that has the characteristics of the text the network was trained on.

A LSTM-network is typically used for the character prediction. The input to the network is just a single character but since the network has an internal state it can remember the previously seen characters. For the "cat" example above the network would be run three times, once for each character, but since the network has an internal state the last iteration would be aware of the entire history. One thing to keep in mind is that during training an unrolled version of the network is used. You unroll maybe 100 iterations into a huge network where the weights are re-used (100 times). The unrolled network accepts 100 inputs and produces 100 outputs, of which only the last one is interesting. A consequence of this is that the network can not learn patterns that do not fit in the unrolled network. If the next character depends heavily on something that happened ~200 characters ago the network would not be able to figure it out because during training it was never able to see that far back in the history.

My network has three layers and each layer has a 512 element state, ~5 million variables. I unroll 175 iterations during training. The loss function is a standard softmax + cross-entropy construction. If you want to have look at the code or try it out yourself the script can be downloaded here.

I trained the network on all the C code in the Linux kernel and after ~24 hours of training it generates text that looks as follows. My script uses the adam optimizer, which gives very quick progress, but it tends to freak out after a while (error in tensorflow's implementation?) so using another optimizer might be a good idea.

static void ct1812_all_channels(struct device *dev, int width, int chan,
                   struct cec_dev *cd, int gpio,
                     struct c41d_spdif_data *data, int di_size)
{
        struct cs42xxxfb_data *ddata = cs5>data->csi2;
        struct fsl_adc_priv *dev = fe->device;

        for (i = 0; i < ARRAY_SIZE(cs45l42_padswrt); i++)
                snd_pcm_csi_buradc(chip->usb_ports[i].pwm, &asus,
                                              CS4231_ISCSI_PKT_AEBA_PG);

        /* Call dis_tdp_queue chained data */
        cs42l42 = cs45;
        dev_dbg(cs->dev, "cc %u rxt %p\n", cs35l33);

        cs428_set_mem_period(cs, csd->msb_cmd, bus, CS35L47_GPT00,
                         bss[i+mips_csio_blk->type]);
}

It looks like C code but if you look at what the code does it makes no sense at all.