Computational Semantics, Fall 2023
Table of Contents
1. Overview
Welcome to Computational Semantics!
I'm Julian Grove, a post-doc in the FACTS.lab directed by Aaron Steven White. I'm teaching Computational Semantics this semester in order for us to explore how functional programming, and specifically the λ-calculus, can be used as a powerful tool in the semantic analysis of natural language, as well as the computational modeling of linguistic behavior.
We'll make heavy use of the Haskell programming language throughout, as we rely on it as a metalanguage to state our theories. Thus the course is aimed primarily at graduate students in Linguistics or Computer Science; but more broadly, it could be interesting to anyone who meets one of the following descriptions:
- has a background in linguistic semantics and hopes to learn (i) how semantic theory can benefit from the incorporation of functional programming techniques; and (ii) how semanticists can benefit from implementing their theories as runnable code
- has a functional programming background and hopes to find out how functional programming techniques have been useful in the analysis of natural language meaning and inference
- has an experimental linguistics background and wants to learn how semantic theory and functional programming can join forces to help vet linguistic theories against experimental data
- wants to learn Haskell
It'll be easier to approach the course if you already have some programming background, though functional programming, per se, isn't necessary. That said, we'll spend the first few classes going over Haskell basics; but we'll launch into the main topics pretty quickly.
The general trajectory of the course will be as follows. In the first part, we'll cover the untyped λ-calculus and type theory. This will take a little bit of time because we'll be building everything from the ground up, covering the syntax of each, as well as their operational semantics and the so-called ``Curry-Howard correspondence''.
In the second part, we'll use the tools developed in the first part in order to study the compositional semantics of natural language (English) by building fragments. We'll enrich our semantic fragments with theories of computational effects; and finally, things will culminate in an approach to theorizing about human linguistic behavior (in an experimental setting) in terms of Bayesian computational models. As we'll see, the theories of computational effects we'll have investigated will be important here.
We'll rely on the following schedule, which I will tweak throughout the semester (though not in any way that affects the basic structure of the course). My general expectation is that everything will take longer than I think it will now.
2. Schedule
Date | Topic | Notes (with exercises) | Resources |
---|---|---|---|
September 6 | Haskell: variables, data types, patterns, and recursion | Sept6 notes | Learn You a Haskell |
August 30 | Formal preliminaries | Practice with sets; Course themes | Partee, Barbara H. and ter Meulen, Alice and Wall, Robert E. (1990) |
September 11 | Haskell: type classes and higher-order polymorphism | Sept11 notes | Learn You a Haskell |
September 13 | Untyped λ-calculus: what is it? | Sept13 notes | Learn You a Haskell |
Septemeber 18 | Untyped λ-calculus: de Bruijn indices | Sept18 notes | Learn You a Haskell, Barendregt: λ-calculi with types, Krivine: λ-caluclus: types and models |
September 20 | Untyped λ-calculus: Church encodings | Sept20 notes | |
Septemeber 25 | Untyped λ-calculus: fixed points and recursive functions | Sept25 notes | |
September 27 | Propositional logic: natural deduction | Sept27 notes | |
October 2 | Propositional logic: structural rules | Oct2 notes | Wadler: A taste of linear logic |
October 4 | Propositional logic: encoding proofs in Haskell, variants of PL | Oct4 notes | |
October 9 | Propositional logic: proofs in Haskell and structural rules | Oct9 notes | |
October 11 | Propositional logic: local completeness | Oct11 notes | |
October 18 | Propositional logic: local soundness | Oct18 notes | Wadler: Propositions as types |
October 23 | Applicative categorial grammar | Oct23 notes | |
October 25 | Model-theoretic fragments, term-theoretic fragments, and the \(\IF{\cdot}\) pipeline | Oct25 notes | |
October 30 | Logical detour: analytic tableaux | Oct30 notes | |
November 1 | Logical detour: implementing tableau rules | Nov1 notes | |
November 6 | Logical detour: monads | Nov6 notes | LYAH on monads |
November 8 | Logical detour: monadic plumbing | Nov8 notes | Code on GitHub |
November 13 | Proof-theoretic fragments | Nov13 notes | |
November 15 | Continuation semantics | Nov15 notes | Barker: Continuations and the nature of quantification, Wadler: Monads and composable continuations |
November 20 | Combining continuation semantics and theorem proving | Nov20 notes | |
November 27 | Probabilistic programming: introduction | Nov27 notes | Grove and White: factivity paper, Grove and Bernardy: Probabilistic compositional semantics, purely |
November 29 | Implementing probabilistic programs in Haskell | Nov29 notes | |
December 4 | Hybrid probabilistic/FOL systems | Dec4 notes | |
December 6 | Encoding a probabilistic knowledge base | Dec6 notes | |
December 11 | Rational Speech Act models via theorem proving | Dec11 notes | |
December 13 | Probabilistic programs as Bayesian models of inference data | Final assignment |
3. Installing Haskell
This course will be Haskell-based, so if you don't have a Haskell development environment installed on your machine, you'll need to install one.
You have a number of options here. One common way to do install Haskell is
using a tool called stack
, which provides the following functionality:
- It supplies ghc, the standard Haskell compiler, along with ghci, its associated interactive environment (i.e., a repl).
- It supplies
base
, the package containing the standard Haskell libraries that go into the default prelude. - It interacts with the Stackage repository, which provides many libraries that you can use in Haskell projects.
- It can be used as a build tool, i.e., to compile binaries, open a repl, provide code documentation (via Haddock) in HTML format from annotated Haskell code.
3.1. Using Windows or Linux
If you are on a Linux distribution or Windows, you should try installing stack manually using these instructions. If you are on Linux and want to install it from a repository provided by your distribution, this is possible, but it can sometimes be difficult to configure properly.
3.2. Using MacOS
If you are on macOS, you can install stack using homebrew
. You should first
install the xcode developer utilities:
$ xcode-select --install
To install homebrew, follow the instructions here. You can then install stack by running:
$ brew install haskell-stack
After doing this, you may need to update gcc, which you can do using homebrew.
Another option for macOS users is to install GHCup
by following the
instructions provided here.
3.3. Using Nix shells
I tend to run Haskell only inside of nix
shells. During development, these
are automatically invoked by Emacs using the amazing dante
package.
The following shell installs base
without any special packages:
let nixpkgs_source = (fetchTarball https://github.com/NixOS/nixpkgs/archive/nixos-23.05.tar.gz); in { pkgs ? import nixpkgs_source { inherit system; } , system ? builtins.currentSystem }: let ghc = pkgs.haskellPackages.ghcWithPackages (ps: with ps; ([ cabal-install ])); in pkgs.stdenv.mkDerivation { name = "my-env-0"; buildInputs = [ ghc ]; shellHook = '' export LANG=C.UTF-8 export LC_ALL=C.UTF-8 eval $(egrep ^export ${ghc}/bin/ghc) ''; }
4. Your development environment
You can develop Haskell code using whatever text editor you want! But for
Haskell, I would very highly recommend Emacs. I use haskell-mode
along with
dante
and attrap
, with the following configuration in my init file:
;; haskell (require 'haskell-mode) (custom-set-variables '(haskell-process-type 'cabal-repl)) (require 'haskell-interactive-mode) (require 'haskell-process) (custom-set-variables '(haskell-process-suggest-remove-import-lines t) '(haskell-process-auto-import-loaded-modules t) '(haskell-process-log t)) (add-hook 'haskell-mode-hook 'interactive-haskell-mode) (defun insert-pragma () (interactive) (insert "{-# LANGUAGE #-}\n") (backward-char 5)) (defun add-haskell-pragma-binding () (local-set-key (kbd "C-x p") #'insert-pragma)) (add-hook 'haskell-mode-hook #'add-haskell-pragma-binding) (defun insert-brackets () (interactive) (insert "{-# #-}") (backward-char 4)) (defun add-haskell-brackets-binding () (local-set-key (kbd "C-x r") #'insert-brackets)) (add-hook 'haskell-mode-hook #'add-haskell-brackets-binding) (defun insert-repl () (interactive) (insert "-- >>> \n") (backward-char 1)) (defun add-haskell-repl-binding () (local-set-key (kbd "C-x i") #'insert-repl)) (use-package dante :after haskell-mode :commands 'dante-mode :init (add-hook 'haskell-mode-hook 'flycheck-mode) (add-hook 'haskell-mode-hook 'dante-mode) (add-hook 'haskell-mode-hook #'add-haskell-repl-binding)) (setq dante-debug '(inputs outputs responses)) (setq dante-repl-command-line '("nix-shell" "--run" "cabal repl")) (use-package attrap :ensure t :bind (("C-x /" . attrap-attrap))) ;; use any binding of your choice
5. Logistics
5.1. Office hours
I'll hold office hours every Monday and Tuesday from 12-1pm. My office is 507 Lattimore Hall.
5.2. Assignments
This course will have weekly pair of assignments (each given at the end of each set of notes), which will be graded Pass/Fail, as well a slightly longer final assignment, which will be given an actual letter grade. Final grades will be calculated taking both into account.
Each assignment will be due a week after it is assigned—so an assignment posted on Monday will be due the following Monday, and an assignment posted on Wednesday will be due the following Wednesday. Assignments can be submitted in class or as a PDF, which you can either email to me or message to me on Zulip.
5.3. Zulip
There is a Zulip for this course. I'll use it to post updates. You should use it to post questions/discussion.
6. Useful resources
Barendregt, Henk P. (2012). The {Lambda} {Calculus}, its {Syntax} and {Semantics}, College Publications.
Blackburn, Patrick and Bos, Johan (2005). Representation and {Inference} for {Natural} {Language}: {A} {First} {Course} in {Computational} {Semantics}, CSLI Publications.
Jansson, Patrik and Ionescu, Cezar and Bernardy, Jean-Philippe (2022). Domain-{Specific} {Languages} of {Mathematics}, College Publications.
Partee, Barbara H. and ter Meulen, Alice and Wall, Robert E. (1990). Mathematical {Methods} in {Linguistics}, Kluwer Academic Publishers.
Thompson, Simon (1999). Type {Theory} \& {Functional} {Programming}.
van Eijck, Jan and Unger, Christina (2010). Computational {Semantics} with {Functional} {Programming}, Cambridge University Press.