This document provides guidelines for maintaining high-quality Python code. These rules MUST be followed by all AI coding agents and contributors.
All code you write MUST be fully optimized.
"Fully optimized" includes:
| #!/usr/bin/env python3 | |
| # /// script | |
| # requires-python = ">=3.9" | |
| # dependencies = [ | |
| # "httpx", | |
| # "typer", | |
| # "rich", | |
| # ] | |
| # /// | |
| """ |
Yoav Goldberg, April 2023.
With the release of the ChatGPT model and followup large language models (LLMs), there was a lot of discussion of the importance of "RLHF training", that is, "reinforcement learning from human feedback". I was puzzled for a while as to why RL (Reinforcement Learning) is better than learning from demonstrations (a.k.a supervised learning) for training language models. Shouldn't learning from demonstrations (or, in language model terminology "instruction fine tuning", learning to immitate human written answers) be sufficient? I came up with a theoretical argument that was somewhat convincing. But I came to realize there is an additional argumment which not only supports the case of RL training, but also requires it, in particular for models like ChatGPT. This additional argument is spelled out in (the first half of) a talk by John Schulman from OpenAI. This post pretty much
| # code to understand product terms and probit models | |
| # clear workspace | |
| rm(list = ls()) | |
| # load packages | |
| library(tidyverse) | |
| library(plotly) | |
| # parameters |
| # metadata | |
| data_source <- "https://docs.google.com/spreadsheets/d/1xa0iLqYKz8x9Yc_rfhtmSOJQ2EGgeUVjvV4A8LsIaxY/htmlview?sle=true#gid=0" | |
| data_collectors <- "Jeremy Pressman (@djpressman, U of Connecticut) and\nErica Chenoweth (@EricaChenoweth, U of Denver)" | |
| code_gist <- "https://gist.github.com/benmarwick/a1ac9c7235ebef542824512162ff2f44" | |
| # ------------------------------------------------------------------------ | |
| # read in data from google sheets to get a data frame |
| group.mean <- function(x, group) { | |
| out <- tapply(x, group, mean, na.rm = TRUE) | |
| out[group] | |
| } | |
| data(state.fips, package = "maps") | |
| state.fips <- unique(state.fips[,c("fips","abb")]) | |
| state.fips$abb <- as.character(state.fips$abb) | |
| state.fips <- rbind(state.fips, c(2, "AK")) | |
| state.fips <- rbind(state.fips, c(15, "HI")) |
| # Simulation script for factor analysis ala Leung & Drton (2016) ---------- | |
| library(rstan) | |
| library(bayesplot) | |
| m <- 5 # dimension of observed data (e.g., # traits) | |
| k <- 2 # number of latent factors | |
| n <- 100 # number of sample units (e.g., # species) | |
| # residual variance matrix (is diagonal) | |
| Omega <- diag(.3 + abs(rnorm(m, sd = .3))) |
| # Check URLs in a document | |
| ## This code will extract URLs from a text document using regex, | |
| ## then execute an HTTP HEAD request on each and report whether | |
| ## the request failed, whether a redirect occurred, etc. It might | |
| ## be useful for cleaning up linkrot. | |
| if (!require("httr")) { | |
| install.packages("httr", repos = "http://cran.rstudio.com/") | |
| } |