Machine Learning

with Functional Programming and F#

Evelina Gabasova (@evelgab)
Tomas Petricek (@tomaspetricek)

About us


Evelina Gabasova

  • Bioinformatics at Cambridge University
  • F# and Machine Learning speaker

Tomas Petricek

  • Trainings and consulting at fsharpWorks
  • Functional languages research
  • F# language and OSS contributor

The F# Software Foundation

www.fsharp.org

The mission of the non-profit F# Software Foundation is to promote, protect, and advance the F# programming language.


  • Independent registered non-profit
  • Open-source community & contributors
  • Microsoft, Xamarin, Tachyus, Jet.com,...

F# for Machine Learning

"F# empowers users to tackle complex computing problems with simple, maintainable and robust code."


What this really means

  • Can implement complex ML algorithms
  • Code is easy to understand
  • We can integrate it with .NET

PART 1

Recognizing languages
using letter pair frequency

The plan

  • Get sample text from from Wikipedia pages (done)
  • Calculate features frequencies of letter pairs
  • Compare languages using their features
  • Classify language find the most similar one

STEP 1

Calculating frequencies

Example using sample English text "the three"


_t

1

th

2

he

1

e_

1

_t

1

hr

1

re

1

ee

1

e_

1

STEP 1

Calculating frequencies

Now calculate probabilities of the pairs


_t

0.11

th

0.22

he

0.11

e_

0.11

_t

0.11

hr

0.11

re

0.11

ee

0.11

e_

0.11

STEP 2

Calculating distance between features

th

e_

ee

el

English

0.3

0.2

0.2

0.1

Portuguese

0.0

0.2

0.1

0.3

Distance is the sum of squares of differences.

STEP 2

Calculating distance between features

th

e_

ee

el

English

0.3

0.2

0.2

0.1

Portuguese

0.0

0.2

0.1

0.3

Difference

0.3

0.0

0.1

-0.2

Sum of squares: \(0.09+0.0+0.01+0.04 = 0.14\)

STEP 3

Classifying unknown text

Portuguese

Spanish

English

Czech

Unknown text

0.10

0.14

0.25

0.27

PART 1

github.com/tpetricek/QCon.Languages

PART 2

Recognizing languages
using simple neural net

How neural networks work

Network with single neuron

Learning the weights

  • Initial weights can be generated randomly
  • Improve weights using gradient descent
  • Repeat recursively until certain error or number of steps

Improving using gradient descent

Gradient descent in more dimensions

Conclusions

Learning more

Learning more about F#

More talks at QCon Rio

  • 10 Ways of Getting Started with F#, Thursday, 12:05
  • Data science the functional way, Friday, 16:45

Web sites to check out

Thank you!


Evelina Gabasova - @evelgab

Tomas Petricek - @tomaspetricek



Personal: evelinag.com | tomasp.net
Work: fsharpworks.com | functional-programming.net