Explanation of using GPT-2 to generate Kant-esque essays

An interesting post on using GPT-2 to generate essays.

The user dljeuni posted a tutorial on the AI Network community forum. It explains how to generate a GPT-2 model that generates essays in the same style as the philosopher Kant would write them.

An interesting tutorial that explains the entire process: pre-processing the data, training, optimizing, and lastly using the data.

dljeuni: I dreamed of someone who writes a Philosophy essay in place of me when I majored in Philosophy. So I came up with the idea that I trained GPT-2 with ‘The Critique of Pure Reason’ of Kant and Kant becomes Ghostwriter and does write Kantian essay in place of students.

Read community post

Leave a Comment

Excellent Article on chatbot best practices

I have been working on chatbots for several months now, and this article I came across is a very good one. The 19 tips are really good en will definitely improve the quality of any chatbot you are building.

At Sabre Labs, we explore how exciting, up-and-coming technologies impact travel. Lately, one of these technologies has been conversational interfaces. We jumped on the chatbot bandwagon with enthusiasm last year, interacting with dozens of chatbots and building several prototypes of our own. Across our research and prototypes it became clear: we still have ways to go before “best practices” for conversational interfaces are established.

19 Best Practices for Building Chatbots

Leave a Comment

MySQL drop all tables in database using queries

During development I sometimes need to drop all tables in a database. When executed, all existing tables are dropped, so be careful executing it.

SET FOREIGN_KEY_CHECKS = 0;
SET GROUP_CONCAT_MAX_LEN=32768;
SET @tables = NULL;
SELECT GROUP_CONCAT('`', table_name, '`') INTO @tables
  FROM information_schema.tables
  WHERE table_schema = (SELECT DATABASE());
SELECT IFNULL(@tables,'dummy') INTO @tables;

SET @tables = CONCAT('DROP TABLE IF EXISTS ', @tables);
PREPARE stmt FROM @tables;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET FOREIGN_KEY_CHECKS = 1;

Via Stackoverflow

Leave a Comment

Convert Windows line endings to Linux line endings using vim

Windows uses the CR/LF characters (Carriage Return and Line Feed) to indicate a line-ending. Under Linux this is only one character, LF. You might see some strange characters at line-endings when editing a file in Linux that was saved in Windows.

To convert these line endings under Linux perform the following steps:

  • Edit the file with vim
  • Give the command :set ff=unix
  • Save the file

Solution Source

Leave a Comment

Dump all Apache requests

On an AWS EC2 instance I needed to find the contents of the X-Forwarded-For header of incoming requests, send by CloudFront. The easiest way was to dump all incoming traffic on port 80:

sudo tcpdump -s 0 -X 'tcp dst port 80' -w dump.pcap

I then copied the dump.pcap to my local machine and loaded it into Wireshark to read its contents.

Solution source

Leave a Comment

Custom cron interval on openshift cron cartridge

Openshift v1 does not allow custom cron times, cronjobs can only be placed in the folders minutely, hourly, daily, weekly and monthly.

You can use the script below to run a cronjob every 5 minutes. You can vary the timestamp by modifying the +4 parameter. The script must be placed in the minutely folder. Here it will run every minute, and write a timestamp to a temporary file. It will check the creation date of the file, and if it is more than 4 minutes ago the cronjob will run. After that the file will be removed and recreated via the touch command.

The example below will run a PHP cronjob.

#!/bin/bash
if [ ! -f $OPENSHIFT_DATA_DIR/last_run ];
then
    touch $OPENSHIFT_DATA_DIR/last_run
    cd $OPENSHIFT_REPO_DIR;php cronjob.php RememberCron
else
 if [[ $(find $OPENSHIFT_DATA_DIR/last_run -mmin +4) ]]; then #run every 5 mins
   cd $OPENSHIFT_REPO_DIR;php cronjob.php RememberCron
   rm -f $OPENSHIFT_DATA_DIR/last_run
   touch $OPENSHIFT_DATA_DIR/last_run
  fi  
fi

Leave a Comment

Mopidy http server on network

I recently installed the mopidy audio player on my raspberry pi to stream music in my livingroom. After installing it it was not immediately clear to me how I could access the installed web client. The example configuration did show an example mpd section with a network config. But that did not make the web interface available at port 6680. It turns out that the http interface has a different config. This is explained in the docs but I did not get that far after the getting started guide. The example below makes mpd listen on all interfaces.

[http]
hostname = ::

Please note that this will make the HTTP server available to every node on the network. This HTTP endpoint will be available without any security protections.

Leave a Comment

Gladys Module Development

The Gladys project is “Your home assistant on your Raspberry Pi built with Node.js”. It allows developers to add new functionality in the form of Modules. This is a small tutorial on getting your environment ready for development of a module.

For now I assume the the following two folders on your filesystem:

A npm install version of Gladys in /home/user/Gladys. (Perform the command npm install gladys in the folder /home/user/gladys). Your own module in /home/user/github/gladys-module. Make sure that you update these paths to your local situation in any code examples you see in this post.

Create a new repository in github where the module will reside. The commands below will initialize a local git repository for the module, and create a NPM module for it. Fill in anything you want for the data requested in the npm init command.

cd /home/user/github/
git clone https://github.com/user/gladys-module
cd gladys-module
npm init

Now we want to be able to easily develop the module within Gladys, we means that we have to be able to update it, inside the folder (/hooks) where Gladys stores the modules. But since git does not allow a git repository within a different repository we take a different approach.

If you did not do this already, configure your local Gladys installation in /home/user/Gladys, as described in the readme.

Module initialization

Place the following index.js file in your module code, commit it and push to Github. This will result in a module which does nothing.

module.exports = function(sails) {
    return {    
    };
}

Run Gladys in development mode

Sails.js is the framework on which Gladys is build. The author of Gladys has provided a simple start-up script to start Gladys in development mode. To run it, simply do: node dev.js. It will generate some output. If you do not have the sails command installed, it will print an error and explain that it needs to be installed. To install it locally run npm install sails, to install globally run sudo npm install -g sails. After running node dev.js, your console window should look something like this:

You can now access your local Gladys installation at http://localhost:1337, lifted means that the server is running.

Install module

Gladys allows you to install a module via the Module store, or via a github URL. The first one is not an option, since the module is in development, it is not available in the store yet. If we install the module via the module Github URL then Gladys will download and install your module.

#Module development The module is now cloned in /home/user/Gladys/api/hooks/. Here you can make changes to it, and when done, commit and push to Github. You can invoke any function you’d like to test from a script, there is no need to reproduce the function hook from Gladys itself. From a script you can use:

gladys.modules.test.function(...)

Where test is the slug of your module, and function is one of the functions exported by your module. Also remember that you need to restart Gladys to apply any changes you have made.

Read more about the subject on the developer documentation. Also look at the existing modules at the Gladys github page.

Leave a Comment

Angular Circular Dependency

In an Angular (1.5) project I recently came across the following error:

16:12:17.669 Error: [$injector:cdep] Circular dependency found: AuthService <- RequestService <- AuthService
http://errors.angularjs.org/1.5.3/$injector/cdep?p0=AuthServic%20%3C-%20RequestService%20%3C-%20AuthService

In this case the problem was related to automatic dependency injection. My AuthService had a dependency on the RequestService to perform a login request. But the RequestService had a dependency on the AuthService to retrieve the accessToken for user-authenticated requests.

The fix was simple, using the $injector. I removed the RequestService dependency from the AuthService, and in the login() function in the AuthService I manually injected the RequestService:

 var RequestService = $injector.get('RequestService');

This bypassed the automatic injection and allowed me to keep using this setup.

Leave a Comment