Skip to content

About

The aim is that by using the pre-supplied code examples, and editing them to examine the different results, you will begin to gain an understand of the techniques used. Go to the Readme file

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

50 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sentiment Analysis

This tutorial on Sentiment Analysis was developed for CDCS by Dave Elsmore (Edina) and updated by Xandra Dave Cochran, Somya Iqbal and Aybuke Atalay. This workshop uses the programming language Python and R to perform some common text analysis tasks. The aim is that by using the pre-supplied code examples, and editing them to examine the different results, you will begin to gain an understand of the techniques used.

Workshop Files

Text Files

CSV Files

Text files with chapter tags

Useful resources and links

If you'd like to continue with text analysis beyond TextBlob used in the notebooks for this session, you may be interested in exploring:

  • NLTK, python natural language toolkit (link)
  • NLTK, freely available book guide (link)
  • NLTK, guide in python (link)
  • spaCY , a python package - includes sentiment analysis (link)

You may be interested in visualisng outputs from your analyses for example a word cloud, or bar charts for positive/negative valence, counts of top terms in your text and so forth:

Note: data should be pre-processed and ready for visualising your final outputs, this can include removing stop words for instance.

  • Matplotlib, a python library for visualising outputs (link)
  • Seaborn, a python library (link)
  • Plotly, a python library for interactive visualisations (link)
  • ggplot2, an R visualisation library (link)

Copyright

This repository has a License: CC BY-NC 4.0 license

How to use this repository

Inside this repository you are going to find a Jupyter Notebook (for python users) and RMarkDown file (for R users) that will allow learning how to perform sentiment analysis and a series of datasets (.txt files). The analysis files work exactly the same and are set to suit preferences for either python or R. If you want more information on how to use RegEx (Regular Expression) via Python you can have a look to this module.

How to use the Jupyter Notebooks (python) & R analyses files

1. Noteable

If you are part of the University of Edinburgh you can use Noteable the cloud-based computational notebook system which works on your browser from any device.

To get started:

Start Noteable (for Python users)

  1. Open the following link in a new tab: https://noteable.edina.ac.uk/login
  2. Login with your EASE credentials
  3. Under 'Standard Notebook' click 'Start'

Start Noteable (for R users)

  1. Open the following link in a new tab: https://noteable.edina.ac.uk/login
  2. Login with your EASE credentials
  3. Under 'RStudio' click 'start'

Upload the Notebook (and files) to Noteable (for R users)

  1. Once you opened RStudio, click on "Project (None)", then click on "New Project"
  2. Select Version Control, then select Git
  3. Under Repository URL, paste https://github.com/DCS-training/SentimentAnalysis
  4. Your project directory name will be automatically created once you paste the URL, you can change it if you want.
  5. Click on Create Project, which will clone the project to Noteable. You will be able to see all the folders and files, including the intro_sentiment_analysis_2026.Rmd, which will be the code that you will be following.

Upload the Notebook (and files) to Noteable (for Python users)

  1. From the Noteable home page, click on the 'Git'>'Clone a Repository' button at the top bar of the screen and enter the link of this repo https://github.com/DCS-training/SentimentAnalysis.git
  2. Now click on Clone
  3. You now have imported the full repo and you can see all the material within the folder names'SentimentAnalysis'
  4. Double-click on 'intro_sentiment_analysis_2026.ipynb' to open the Notebook for Python and 'intro_sentiment_analysis_2026.Rmd' if following the R version of this analysis.
  5. Follow the instruction on the Notebook
Noteable is the reccomended mode for University members since your EASE credentials provide easy access to the analysis and avoid further installation of any software or tools locally.

2. Installing Python via Anaconda

Python is great for general-purpose programming and is a popular language for scientific computing as well. Installing all of the packages required for this lessons individually can be a bit difficult, however, so we recommend the all-in-one installer Anaconda.

Regardless of how you choose to install it, please make sure you install Python version 3.x (e.g., Python 3.6 version).

Windows - Video tutorial

  1. Open anaconda.com/download with your web browser.

  2. Download the Python 3 installer for Windows.

  3. Double-click the executable and install Python 3 using MOST of the default settings. The only exception is to check the Make Anaconda the default Python option.

  1. Open anaconda.com/download with your web browser.

  2. Download the Python 3 installer for macOS.

  3. Install Python 3 using all of the defaults for installation.

Starting Python

To start Jupyter Notebook Open the Anaconda Navigator and Launch Jupyter Notebook

Upload the Notebook

  1. Download the notebook on your machine
  2. Go to Upload
  3. Navigate to where you have download your file
  4. Select Upload again
  5. Double click on the uploaded file

3. Run the notebooks via GoogleColab

Open Google Colab: https://colab.research.google.com If you are not already logged you will be prompted to log-in via gmail

Upload the Notebook to Noteable

  1. Go on the GitHub header and copy paste the link to the notebook you want to use and press enter

4. Using the Notebook

The Notebook contains paragraphs of explanatory text interspersed with grey cells containg code blocks. To run a code block and see the result:

  1. Place your cursor within the cell
  2. Click the 'Run' button on the top menu
  3. The results of running this code will appear below
  4. if the results don't appear immediately, check the icon in the browser tab. AN eggtimer icon indicates it is processing the code.
  5. It is best to follow the Notebook from top to bottom as some code blocks will depend on results from previous cells
  6. You can edit code blocks yourself and run them to see the results of your changes

5. Clearing the cells

To clear the results and run the code again you can use the 'Cell' menu on the top menu bar

  1. To clear the results of the current cell: Cell > Current Outputs > Clear
  2. To clear the results of all cells: Cell > All Output > Clear

About

The aim is that by using the pre-supplied code examples, and editing them to examine the different results, you will begin to gain an understand of the techniques used. Go to the Readme file

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Contributors

Languages