Introduction, Programming, Python. Michael Mandel Lecture 1 Methods in Computational Linguistics I The City University of New York, Graduate Center

Similar documents
Introduction to Computer Programming for Non-Majors CSC 2301, Fall The Department of Computer Science

Introduction to Computer Programming for Non-Majors

The >>> is a Python prompt indicating that Python is ready for us to give it a command. These commands are called statements.

STEAM Clown & Productions Copyright 2017 STEAM Clown. Page 1

Python Programming: An Introduction to Computer Science

CS 190C: Introduction to Computational Thinking

CSC 015: FUNDAMENTALS OF COMPUTER SCIENCE I

Outline: Search and Recursion (Ch13)

L435/L555. Dept. of Linguistics, Indiana University Fall 2016

Loop structures and booleans

Scientific Computing: Lecture 1

Starting. Read: Chapter 1, Appendix B from textbook.

CSI31 Introduction to Computer Programming I. Dr. Sharon Persinger Fall

Python for Analytics. Python Fundamentals RSI Chapters 1 and 2

File processing and decision structures

CS 432 Fall Mike Lam, Professor. Compilers. Advanced Systems Elective

Lecture 1. basic Python programs, defining functions

COMP-202: Foundations of Programming. Lecture 2: Java basics and our first Java program! Jackie Cheung, Winter 2016

CS2900 Introductory Programming with Python and C++ Kevin Squire LtCol Joel Young Fall 2007

Programming for Engineers in Python

If Statements, For Loops, Functions

Master of Engineering in Computer Engineering Orientation. August 22, Pierce Cantrell Department of Electrical and Computer Engineering

Class overview today - September 6, 2017

CS1 Lecture 3 Jan. 22, 2018

CSI Lab 02. Tuesday, January 21st

Python Programming: An Introduction to Computer Science. John M. Zelle, Ph.D.

Week - 01 Lecture - 04 Downloading and installing Python

CS187 - Science Gateway Seminar for CS and Math

CS 240 Fall Mike Lam, Professor. Just-for-fun survey:

CS 432 Fall Mike Lam, Professor. Compilers. Advanced Systems Elective

CS 241 Data Organization. August 21, 2018

CS1 Lecture 3 Jan. 18, 2019

CS 3030 Scripting Languages Syllabus

CS 177 Recitation. Week 1 Intro to Java

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

COMP-202: Foundations of Programming. Lecture 2: Java basics and our first Java program! Jackie Cheung, Winter 2015

CME 193: Introduction to Scientific Python Lecture 1: Introduction

Intro to Computer Science. Introductory Class

Semantics of programming languages

Lastly, in case you don t already know this, and don t have Excel on your computers, you can get it for free through IT s website under software.

Introduction to Scientific Python, CME 193 Jan. 9, web.stanford.edu/~ermartin/teaching/cme193-winter15

Part III Appendices 165

Semantics of programming languages

CSC 111 Introduction to Computer Science (Section C)

CS1 Lecture 2 Jan. 16, 2019

Intro to Python Programming

1. BASICS OF PYTHON. JHU Physics & Astronomy Python Workshop Lecturer: Mubdi Rahman

Welcome to Blackboard

(Ca...

CS 378 (Spring 2003) Linux Kernel Programming. Yongguang Zhang. Copyright 2003, Yongguang Zhang

CS Compiler Construction West Virginia fall semester 2014 August 18, 2014 syllabus 1.0

Course Syllabus. Programming Language Paradigms. Spring - DIS Copenhagen. Semester & Location: Elective Course - 3 credits.

CSE 101 Introduction to Computers Development / Tutorial / Lab Environment Setup

CS535: Interactive Computer Graphics

Masters in Software Engineering

Lecture. Algorithm Design and Recursion. Richard E Sarkis CSC 161: The Art of Programming

CS 3813/718 Fall Python Programming. Professor Liang Huang.

How to Think Like a Computer Scientist: Learning with Python 3»

CS102 Unit 2. Sets and Mathematical Formalism Programming Languages and Simple Program Execution

CSc 10200! Introduction to Computing. Lecture 1 Edgardo Molina Fall 2013 City College of New York

Compilers for Modern Architectures Course Syllabus, Spring 2015

These are notes for the third lecture; if statements and loops.

Lecture 3: Functions & Modules

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

Programming. We will be introducing various new elements of Python and using them to solve increasingly interesting and complex problems.

San José State University Department of Computer Science CS151, Section 04 Object Oriented Design Spring 2018

CS1 Lecture 5 Jan. 25, 2019

Masters in Advanced Computer Science

3D Graphics Programming Mira Costa High School - Class Syllabus,

Introduction to Programming

Exercises: Instructions and Advice

COMP 250. Lecture 36 MISC. - beyond COMP final exam comments

CS110/CS119 Introduction to Computing (Java) Bob Wilson S-3-176

DEPARTMENT OF COMPUTER SCIENCE

Introduction to Programming with JES

Page 1. Welcome! Lecture 1: Interfaces & Users. Who / what / where / when / why / how. What s a Graphical User Interface?

CSC290 Communication Skills for Computer Scientists

Research Computing with Python, Lecture 1

Lab 1: Setup 12:00 PM, Sep 10, 2017

CS/SE 153 Concepts of Compiler Design

Chris Simpkins (Georgia Tech) CS 2316 Data Manipulation for Engineers Python Overview 1 / 9

Class 1: Homework. Intro to Computer Science CSCI-UA.0101 New York University Courant Institute of Mathematical Sciences Fall 2017

The Linux Command Line: A Complete Introduction, 1 st ed., by William E. Shotts, Jr., No Starch Press, 2012.

STAT 213: R/RStudio Intro

Semester 2, 2018: Lab 1

Getting Started with Python

ENCE 688R Civil Information Systems

DSC 201: Data Analysis & Visualization

Introduction to computers and Python. Matthieu Choplin

Grade 6 Math Circles November 6 & Relations, Functions, and Morphisms

(0) introduction to the course. how to learn a programming language. (0) course structure

Part 1 - Your First algorithm

PC Applications IT102 estart Fall 2014

Lecture 3: Processing Language Data, Git/GitHub. LING 1340/2340: Data Science for Linguists Na-Rae Han

Programming: detailed instructions which tell the computer hardware what to do aka software Computer Science: the study NOT of computers, but of what

Department of Accounting & Law, School of Business. State University of New York at Albany. Acc 682 Analysis & Design of Accounting Databases

SAMS Programming A/B. Lecture #1 Introductions July 3, Mark Stehlik

Professor Hugh C. Lauer CS-1004 Introduction to Programming for Non-Majors

Lesson 1A - First Java Program HELLO WORLD With DEBUGGING examples. By John B. Owen All rights reserved 2011, revised 2015

Welcome to Computer Organization and Design Logic

Transcription:

Introduction, Programming, Python Michael Mandel Lecture 1 Methods in Computational Linguistics I The City University of New York, Graduate Center

Outline Class Information Introduction to Computer Science Programming Languages First Look at Python Inside a Python Program

Class Information

About me Michael Mandel Assistant Professor of Computer Science at Brooklyn College Faculty in GC PhD programs in Computer Science and Linguistics Email: mim@sci.brooklyn.cuny.edu Website: http://mr-pc.org Research: machine listening in noisy environments Speech enhancement via synthesis Noise robust automatic speech recognition Microphone array processing for source separation Understanding human noise robustness using psychoacousics

Office Hours By appointment. (Send me an e-mail.) After class is a good time for me, before is ok Office: GC room 4410

Introductions Your Name Your Program at Grad Center Taking this class for credit, or auditing? How much programming experience do you have? Research interests? What are you goals and expectations for this class?

Course Syllabus A course outline is available on the course website: http://mr-pc.org/t/ling78100 But let s go over it now.

Website, GitHub classroom, BlackBoard The full syllabus, PowerPoint lecture slides, and PDFs of assignments will be posted on the course website Assignments will be distributed from the course website and will be collected on GitHub classroom. More details will follow. We may use CUNY's Blackboard system for submissions You should get your BlackBoard account set up if you haven t yet. You can log into Blackboard via CUNY Portal

Pre/Co-requisites Practicum Session: Tuesdays, room 7395, 4:15pm 6:15pm Hussein Ghaly, PhD student, Linguistics Programming practice, review of topics Required co-requisite This course is a prerequisite for Methods 2 Usually taught in the spring semester. This course is a recommended prerequisite for Language Technologies Usually taught in the fall semester.

Class Schedule No lecture on: September 4 October 9 No practicum on: September 19 November 21

NLP at CUNY http://nlpatcuny.cs.qc.cuny.edu/ (a bit out of date) Seminar Series: CUNY-NLP specific dates and times TBD Computational Linguistics Faculty William Sakas, Virgina Teller, Martin Chodorow, Jia Xu, Rivka Levitan, Michael Mandel, Elena Filatova Other useful courses: Language Technology, machine learning, statistics, further courses in linguistics, other languages.

About the class Title of this class is a misnomer should be Python 101 Learning tools you will need for comp ling, not comp ling itself How to get involved in comp ling? Come to NLP talks! Come to reading group! Ask questions!

Computational Linguistics Reading Group Specific dates and times TBD, Linguistics thesis room Except on day when there are NLP talks happening Organized by Rachel Rakov, PhD student in Linguistics Great opportunity to keep up on new research in the field, or to review old research, or get opinions on topics Not required, but recommended

K. McCoy, U. Delaware Computational Linguistics The study of what goes into getting computers to perform useful and interesting tasks involving human languages. The insights that such computational work gives us into human processing of language. Other Names for Computational Linguistics: Natural Language Processing (NLP) Human Language Technology (HLT) Or just Language Technology (LT) Natural Language Engineering (NLE) Speech and Text Processing

Why is NLP important? Lots and lots of language data (in machine-readable form)! Too much for humans to read and process on our own Improve digitally mediated communication Both human-to-human and human-to-computer Language is complicated! Linguists can test theories of language and see if they work on a larger scale Computer scientists can build more useful structures if they know how to handle language These tasks are best handled by a combination of linguistic and probabilistic knowledge.

Knowledge, Language, and NLP Natural Language (NL) is the preferred way for humans to store and exchange information. NL = real language people grow up using (e.g. French). People don t generally record or send information in the form of logical predicates or formal/computer languages. Computers normally store/input/output information in ways not closely related to human language. Binary numbers Data Structures Logic Languages Natural Language Processing (NLP) is the study of how computers can process natural languages. People could interact with computers using language. Allow computers to use information written in language.

Two Motivations for Studying NLP From the Linguistics side Computer modeling of natural language is one way of understanding human cognitive structure/processing. We can test a theory of how language works and see if it works well when we write a program using our theory. From the CS side Computers would be easier to use if humans could use natural language to interact with them. Language is very natural to humans. This can make computers come to meet us rather than us go to meet them. Computers can take advantage of information sources (e.g. the WWW) that humans have written in language. Computers can do cool things if they process language.

Applications of NLP What are some useful things NLP can do? Analyzing sentences and words parsing, part-of-speech tagging, morphology Information Extraction, Named Entity Recognition Summary Generation Machine Translation Document Organization/Classification Information Retrieval Database Interfaces, Question Answering Text Editing, Grammar/Style Checking And that s not even getting into speech

This Course Programming Boot Camp Accelerated introduction to programming Using the Python Programming Language Useful language for Computational Linguistics Valuable for many other forms of research Introduction to a few computational linguistic concepts through the use of examples. Main focus: computer programming, good style, data structures, key computer concepts, key math concepts, etc.

Introduction to Computer Science

Objectives To understand the respective roles of hardware and software in a computing system. To learn what computer scientists study and the techniques that they use. To understand the basic design of a modern computer. To understand the form and function of computer programming languages. To begin using the Python programming language.

The Universal Machine A modern computer can be defined as a machine that stores and manipulates information under the control of a changeable program. Two key elements: Computers are devices for manipulating information. Computers operate under the control of a changeable program.

The Universal Machine What is a computer program? A detailed, step-by-step set of instructions telling a computer what to do. If we change the program, the computer performs a different set of actions or a different task. The machine stays the same, but the program changes!

The Universal Machine Programs are executed, or carried out. All computers have the same power, with suitable programming, i.e. each computer can do the things any other computer can do.

Program Power Software (programs) rule the hardware (the physical machine). The process of creating this software is called programming. Why learn to program? Fundamental part of computer science Having an understanding of programming helps you have an understanding of the strengths and limitations of computers.

Program Power Helps you become a more intelligent user of computers It can be fun! Form of expression Helps the development of problem solving skills, especially in analyzing complex systems by reducing them to interactions between simpler systems. Programmers are in great demand!

What is Computer Science? It is not the study of computers! Computers are to computer science what telescopes are to astronomy. E. Dijkstra The question becomes, What processes can be described? This question is really, What can be computed?

What is Computer Science? Design One way to show a particular problem can be solved is to actually design a solution. This is done by developing an algorithm, a step-by-step process for achieving the desired result. One problem it can only answer in the positive. You can t prove a negative!

What is Computer Science? Analysis Analysis is the process of examining algorithms and problems mathematically. Some seemingly simple problems are not solvable by any algorithm. These problems are said to be unsolvable. Problems can be intractable if they would take too long or take too much memory to be of practical value.

What is Computer Science? Experimentation Some problems are too complex for analysis. Implement a system and then study its behavior.

Programming languages

Programming Languages Natural language has ambiguity and imprecision problems when used to describe complex algorithms. Programs expressed in an unambiguous, precise way using programming languages. Every structure in programming language has a precise form, called its syntax Every structure in programming language has a precise meaning, called its semantics.

Programming Languages Programming language like a code for writing the instructions the computer will follow. Programmers will often refer to their program as computer code. Process of writing an algorithm in a programming language often called coding.

Programming Languages High-level computer languages Designed to be used and understood by humans Low-level language Computer hardware can only understand a very low level language known as machine language

Programming Languages Add two numbers: Load the number from memory location 2001 into the CPU Load the number from memory location 2002 into the CPU Add the two numbers in the CPU Store the result into location 2003 In reality, these low-level instructions are represented in binary (1 s and 0 s)

Programming Languages High-level language c = a + b This needs to be translated into machine language that the computer can execute. Compilers convert programs written in a high-level language into the machine language of some computer.

Programming Languages Interpreters simulate a computer that understands a high-level language. The source program is not translated into machine language all at once. An interpreter analyzes and executes the source code instruction by instruction.

Programming Languages Compiling vs. Interpreting Once program is compiled, it can be executed over and over without the source code or compiler. If it is interpreted, the source code and interpreter are needed each time the program runs Compiled programs generally run faster since the translation of the source code happens only once.

Programming Languages Interpreted languages are part of a more flexible programming environment since they can be developed and run interactively Interpreted programs are more portable, meaning the executable code produced from a compiler for a Pentium won t run on a Mac, without recompiling. If a suitable interpreter already exists, the interpreted code can be run with no modifications.

First look at python

The Magic of Python When you start Python in a terminal, you will see something like: Python 3.5.1 (v3.5.1:37a07cee5969, Dec 6 2015, 01:54:25) [MSC v.1900 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. >>>

The Magic of Python Jupyter notebooks allow you to edit and run code in the browser Flexible way to demonstrate code and share results Widely known and supported, GitHub makes it easy to share I will demonstrate the code for this course using notebooks and share links to the final version with you Practicum 1 will help you setup jupyter on your computer

The Magic of Python The >>> is a Python prompt indicating that Python is ready for us to give it a command. These commands are called statements. >>> print("hello, world") Hello, world >>> print(2+3) 5 >>> print("2+3=", 2+3) 2+3= 5 >>>

The Magic of Python Usually we want to execute several statements together that solve a common problem. One way to do this is to use a function. >>> def hello(): print("hello") print("computers are Fun") >>>

The Magic of Python >>> def hello(): print("hello") print("computers are Fun") >>> The first line tells Python we are defining a new function called hello. The following lines are indented to show that they are part of the hello function. The blank line (hit enter twice) lets Python know the definition is finished.

The Magic of Python >>> def hello(): print("hello") print("computers are Fun") >>> Notice that nothing has happened yet! We ve defined the function, but we haven t told Python to perform the function! A function is invoked (or called) by typing its name. >>> hello() Hello Computers are Fun >>>

The Magic of Python What s the deal with the () s? Commands can have changeable parts called parameters (or arguments) that are placed between the () s. >>> def greet(person): print("hello",person) print ("How are you?") >>>

The Magic of Python >>> greet("terry") Hello Terry How are you? >>> greet("paula") Hello Paula How are you? >>> When we use parameters, we can customize the output of our function.

The Magic of Python When we exit the Python prompt, the functions we ve defined cease to exist! Programs are usually composed of functions, modules, or scripts that are saved on disk so that they can be used again and again. A module file is a text file created in text editing software (saved as plain text ) that contains function definitions. A programming environment is designed to help programmers write programs and usually includes automatic indenting, highlighting, etc.

The Magic of Python # File: chaos.py # A simple program illustrating chaotic behavior def main(): print("this program illustrates a chaotic function") x = eval(input("enter a number between 0 and 1: ")) for i in range(10): x = 3.9 * x * (1 - x) print(x) main() We ll use filename.py when we save our work to indicate it s a Python program. In this code we re defining a new function called main. The main() at the end tells Python to run the code.

The Magic of Python >>> This program illustrates a chaotic function Enter a number between 0 and 1:.5 0.975 0.0950625 0.335499922266 0.869464925259 0.442633109113 0.962165255337 0.141972779362 0.4750843862 0.972578927537 0.104009713267 >>>

Inside a python program

Inside a Python Program # File: chaos.py # A simple program illustrating chaotic behavior Lines that start with # are called comments Intended for human readers and ignored by Python Python skips text from # to end of line

Inside a Python Program def main(): Beginning of the definition of a function called main Since our program has only this one module, it could have been written without the main function. The use of main is customary, however.

Inside a Python Program print("this program illustrates a chaotic function") This line causes Python to print a message introducing the program.

Inside a Python Program x = eval(input("enter a number between 0 and 1: ")) x is an example of a variable A variable is used to assign a name to a value so that we can refer to it later. The quoted information is displayed, and the number typed in response is stored in x.

Inside a Python Program for i in range(10): For is a loop construct A loop tells Python to repeat the same thing over and over. In this example, the following code will be repeated 10 times.

Inside a Python Program x = 3.9 * x * (1 - x) print(x) These lines are the body of the loop. The body of the loop is what gets repeated each time through the loop. The body of the loop is identified through indentation. The effect of the loop is the same as repeating these two lines 10 times!

Inside a Python Program for i in range(10): x = 3.9 * x * (1 - x) print(x) These are equivalent! x = 3.9 * x * (1 - x) print(x) x = 3.9 * x * (1 - x) print(x) x = 3.9 * x * (1 - x) print(x) x = 3.9 * x * (1 - x) print(x) x = 3.9 * x * (1 - x) print(x) x = 3.9 * x * (1 - x) print(x) x = 3.9 * x * (1 - x) print(x) x = 3.9 * x * (1 - x) print(x) x = 3.9 * x * (1 - x) print(x) x = 3.9 * x * (1 - x) print(x)

Inside a Python Program x = 3.9 * x * (1 - x) This is called an assignment statement The part on the right-hand side (RHS) of the "=" is a mathematical expression. * is used to indicate multiplication Once the value on the RHS is computed, it is stored back into (assigned) into x

Inside a Python Program main() This last line tells Python to execute the code in the function main

Summary

Outline Class Information Introduction to Computer Science Hardware Basics Programming Languages First Look at Python Inside a Python Program

Things to do... Readings from Textbook for next time: Chapter 1, Chapter 2, Chapter 3 Practicum 1 Install python via Anaconda Install Jupyter notebooks Install nltk Install GitHub Desktop Play around with some Python commands

Any Questions?

Acknowledgements Slides adapted & reused from Rachel Rakov's Methods in Computational Linguistics 1 course, Fall 2016 Some slides in this presentation have been adapted from the following sources: Python Programming: An Introduction to Computer Science (third edition) textbook slides, by John Zelle, Franklin, Beedle & Associates, http://mcsp.wartburg.edu/zelle/python/