Skip to content

Plutonic Rainbows

Flagging Extremist Content

Great article from ASI Data Science on Binary Classification and ROC Curves.

It is well known that online propaganda from terrorist organisations plays a key part in radicalisation in Europe and the UK. In collaboration with the UK Home Office, we recently developed and tested an AI algorithm designed to detect such propaganda on the web.

Following media coverage of the classifier (see, for example, BBC News and The Guardian), there has been much talk of how it works and its performance. In this post, without exposing the inner workings of the algorithm, we'll do our best to outline the general approach we took to design the classifier. We also specify precisely the metrics used and the performance achieved by the classifier.

Counting Things

This (fairly) simple few lines calculates the days between two dates - in this case, the 4th of July 2020. That's 888 days as of February 13th 2018.

from datetime import *

today = date.today()
future = date(2020,07,20)

diff = future - today

print "There are %s days left." % diff.days

Loan Calculator

Using the Functions available for Maths, I built a simple loan calculator -including the elif and else statements so that Python can make a decision. I am sure there are much simpler ways of doing this but as I am still learning, it's all I can do right now.

# -*- coding: utf-8 -*-

def amount_to_borrow(loan_request, twelve_months):
    print "Calculating 12 months interest totalling £{0:.2f}.\n".format (twelve_months)
    return loan_request + twelve_months


loan_request = (float(raw_input("How much do you want?\nEnter Amount: ")))

monthly_payments = loan_request / 12

twelve_months = monthly_payments + 15.00 * 12

interest_payments = 15 * 12

total = amount_to_borrow(loan_request, twelve_months)

raw_input("Press Return to get your decision.\n")

credit_limit = 5000

print "The cost of your loan is £{0:.2f}\n".format (total)
print "That's £{0:.2f} in 12 monthly payments".format (monthly_payments)
print "And £{0:.2f} in Interest Payments over 12 months.\n".format (interest_payments)
print "The limit for your account is £{0:.2f}\n".format (credit_limit)

if total < credit_limit:
    print "Your loan is approved.\n"

elif total > credit_limit:
    print "Sorry. You are not approved.\n"

else:
    print "Please come into the branch to discuss it.\n"

Using Functions to do Maths

Mathematics isn't really something I'm good at but luckily, Python makes it easy when using functions. I'm also using .format to correctly show decimal places - as well as # -*- coding: utf-8 -*- so that Python can print currency symbols..

# -*- coding: utf-8 -*-
def add(a, b, c):
    print "\nADDING %d + %d + %d" % (a, b, c)
    return a + b + c

price = add(12, 12, 12);print "The price is £{0:.2f}\n".format (price)

def multiply(a, b):
    print "MULTIPLYING %d * %d" % (a, b)
    return a * b

multiply_price = multiply(10, 10);print "The price is £{0:.2f}\n".format (multiply_price)

def subtracting(a, b):
    print "SUBTRACTING %d - %d" % (a, b)
    return a - b

subtract_price = subtracting(100, 50);print "The price is £{0:.2f}\n".format (subtract_price)

def division(a, b):
    print "DIVIDING %d / %d" % (a, b)
    return a / b

division_price = division(90, 2);print "The price is £{0:.2f}\n".format (division_price)

Rewinding

This will not sink in. Have to keep looking at it over and over again. I'm just not clever enough, I think. The only way to make it stick is to look at the previous variables etc.

from sys import argv

script, input_file = argv

def print_all(f):
    print f.read()

def rewind(f):
    f.seek(0)

def print_a_line(line_count, f):
    print line_count, f.readline()

current_file = open(input_file)

print "First let's print the whole file:\n"

print_all(current_file)

print "\nNow let's rewind. Just like a tape."

rewind(current_file)

print "Let's print three lines:\n"

current_line = 1
print_a_line(current_line, current_file)

current_line = current_line + 1
print_a_line(current_line, current_file)

current_line = current_line + 1
print_a_line(current_line, current_file)

print "\n"

Defining a Function

Ended the week with revision. Have to build this into learning if I want to remember what I've studied.

Defining a function:

def print_three(arg1, arg2, arg3):
    print "Name: %r, Surname: %r, Country: %r" % (arg1, arg2, arg3)

print_three("Elle", "Macpherson", "Australia")

Copying Files

Learning how to copy files with Python. The script also checks the file size in bytes.

from sys import argv
from os.path import exists

script, from_file, to_file = argv

print "Let's copy from %s to %s." % (from_file, to_file)

in_file = open(from_file)
indata = in_file.read()

print "The size is %s bytes in length." % len(indata);
print "Does the target file exist? %r" % exists (to_file)

raw_input()

out_file = open(to_file, 'w')
out_file.write(indata)

in_file.close()
out_file.close()

print "All done."

Kuniyuki Takahashi - Early Tape Works 1986 - 1993 Volume 1

Bleep:

The Amsterdam crew delve deep into the archives of Japanese deep house sensation Kuniyuki to bring us six entrancing early compositions. MFM027 collects some of the choice early recordings from a man known for his expert sound design and earthy, percussive leaning dance tracks. The songs that Tako & Jamie Tiller have opted for show a rough and slightly amateur sounding approach to the stylistic traits that would go on to define a career. Blurring the lines between kosmiche, ambient, dub and electro this record is top quality as you’ve no doubt come to expect from the label.

Vinyl & Digital from Bleep

The Radiophonic Workshop - Burials In Several Earths

Boomkat:

Burials In Several Earths is a brand new work by the legendary Radiophonic Workshop. Nearly two decades after the Workshop was decommissioned, original members Peter Howell, Roger Limb, Dr Dick Mills, Paddy Kingsland and long-time associate composer Mark Ayres are back working together, featuring guest appearances from Martyn Ware and Steve ‘Dub’ Jones, creative an evocative suite of synth improvisations.

At first glance a new album from The Radiophonic Workshop may be viewed as something of a surprise, arriving long after the pioneering group’s last long player together. But it does make sense. A fair chunk of modern day archivalism has rightly focused on the group’s work for the BBC, after the workshop was established by Desmond Briscoe and Daphne Oram in the late ‘50s and crafted soundtracks that were well ahead of their time. This renewed interest led to core original members reconvening The Radiophonic Workshop in 2012 to undertake a series of live performances.

From this we now have Burials In Several Earths, released on the group’s own Room 13 label - the name a canny nod to the BBC Maida Vale studio where they did so much great work. Recorded with celebrated engineer Steve ‘Dub’ Jones and Human Leaguer Martyn Hare, this album finds the veteran work shoppers freed from the constraints of working to a script and expressing their creativity in a spontaneous manner. The resultant five tracks occupy a strange – but totally alluring – place; sat somewhere between the Workshop’s own iconic work and a cadre of modern day practitioners who have undoubtedly been profoundly influenced by them, such as Pye Corner Audio, and Alessandro Cortini.

Pool Boy - Pool Boy LP

Apparently Deluxe Oceanview was created in, and inspired by, a coastal Vancouver view, but the label upon which Pool Boy LP was released (Coastal Haze) is keeping the identity of the producer a secret.