Personal
Introducing `askgpt`: a chat interface that helps you to learn R!
Everyone is talking about AI at the moment. So when I talked to my collogues Mariken and Kasper the other day about how to make teaching R more engaging and how to help students overcome their problems, it is no big surprise that the conversation eventually found it’s way to the large language model GPT-3.5 by OpenAI and the chat interface ChatGPT. It’s advantages for learning R (or any programming languages) are rather obvious: you get help on exactly your path to learning – which is different for everyone of us you can ask the model anything without anxiety about what it might think of you it can answer instantaneously So I got to work implementing a few of the functionalities I wish I had available when I first started with R. The resulting package was just released on CRAN and I wanted to write this post to highlight a few of the way you can use it to make learning or teaching easier. You can install it now like so install.packages("askgpt") Or get the development version: remotes::install_github("JBGruber/askgpt") A Simple Chat Interface Directly in R The main function, askgpt(), is very similar to ChatGPT, only directly in R: library(askgpt) askgpt("Can you explain how functions work in R?") #> Functions in R are a set of pre-defined or user-defined set of instructions that can take inputs, perform specific calculations or operations, and return outputs. Functions can be used to automate repetitive tasks, combine multiple operations into a single step, and create more complex programs. #> #> In R, function definitions can be created using the `function()` keyword. The basic syntax of a function definition in R is as follows: #> #> ``` #> function_name # Function code goes here #> return(output) #> } #> ``` #> #> Here, `function_name` is the name you choose for your function, `argument1`, `argument2`, etc. are the inputs to the function (also called parameters), and `output` is the value that the function returns. #> #> To use a function in R, you simply call it by its name and supply any necessary arguments: #> #> ``` #> function_name(argument1, argument2, ...) #> ``` #> #> R has a large number of built-in functions that perform a wide variety of tasks. For example, the `sum()` function adds up all the values of a given vector, while the `mean()` function calculates the average. #> #> In addition to using pre-defined functions in R, you can also create your own custom functions based on your specific needs. By combining multiple functions and operations in a single custom function, you can create powerful tools for data analysis and modeling. askgpt("How do you make a histogram with ggplot2?") #> To make a histogram with ggplot2, follow these steps: #> #> 1. Load the ggplot2 library using the `library()` function. #> ``` #> library(ggplot2) #> ``` #> #> 2. Prepare your data. Create a vector or data frame that contains the values you want to plot. #> #> 3. Create a ggplot object using the `ggplot()` function. Pass in the name of the data frame as an argument. #> #> ``` #> ggplot(data = your_data_frame) #> ``` #> #> 4. Add a histogram layer to the plot using the `geom_histogram()` function. Pass in the name of the column you want to use for your histogram as the `mapping` argument. #> #> ``` #> ggplot(data = your_data_frame, #> mapping = aes(x = your_column_name)) + #> geom_histogram() #> ``` #> #> 5. Customize the plot as desired using various ggplot2 functions, such as `labs()` for axis labels and titles, `theme()` for plot themes, and `scale_x_continuous()` and `scale_y_continuous()` for adjusting the axis limits and tick marks. #> #> ``` #> ggplot(data = your_data_frame, #> mapping = aes(x = your_column_name)) + #> geom_histogram() + #> labs(x = "X axis label", #> y = "Y axis label", #> title = "Histogram Title") + #> theme_bw() + #> scale_x_continuous(limits = c(0, 100), #> breaks = seq(0, 100, 10), #> expand = c(0, 0)) + #> scale_y_continuous(limits = c(0, 20), #> breaks = seq(0, 20, 2), #> expand = c(0, 0)) #> ``` #> #> 6. Use the `ggsave()` function to save the plot to a file. #> #> ``` #> ggsave(file = "path/to/save/file.png", width = 6, height = 4, dpi = 300) #> ``` #> #> Note: Replace `your_data_frame` and `your_column_name` with the actual names of your data frame and column, respectively. Adjust the axis limits and tick marks according to your needs. To make setting things up as easily as possible, the above lines will prompt you to log into your OpenAI account and generate an API key that is automatically saved for the future once entered into RStudio. The chat also remembers the previous conversation, so you can always ask it to elaborate or explain something differently. askgpt("I don't understand what you mean. Can you explain this for beginners?") #> Sure, let's break down the steps to create a histogram using ggplot2 in R for beginners: #> #> 1. First, you need to load the ggplot2 package in your R session. You can do this by running the following command: #> #> ``` #> library(ggplot2) #> ``` #> #> 2. Next, you need to import or create a data frame that contains the data you want to plot. For example, let's create a vector of random numbers using the `rnorm()` function: #> #> ``` #> my_data ``` #> #> This creates a vector of 1000 normal-distributed random numbers with a mean of 10 and a standard deviation of 2. #> #> 3. Now, you can create a basic ggplot object using the `ggplot()` function, passing in the name of the data frame as an argument: #> #> ``` #> my_plot ``` #> #> 4. Then, you can add a histogram layer on top of the ggplot object using the `geom_histogram()` function: #> #> ``` #> my_plot ``` #> #> Here, `binwidth` is an argument that specifies the size of each histogram bin - we've set it to 0.5, but you can adjust it depending on your data. #> #> 5. Finally, you can customize the histogram by adding axis labels, a title, changing the bin width, etc. Here's an example: #> #> ``` #> my_plot geom_histogram(binwidth = 0.5, fill = "blue", #> alpha = 0.5, colour = "black") + #> labs(title = "My Histogram", x = "Values", y = "Frequency") #> ``` #> #> In this example, we've added axis labels and a title to the plot, set the bin width to 0.5, filled the histogram bars with blue and made them semi-transparent with `alpha`, and set the border color to black. #> #> 6. You can then display the plot using `print(my_plot)` or simply `my_plot`. #> #> ``` #> print(my_plot) #> ``` #> #> 7. If you want to save the plot to your computer, you can use the `ggsave()` function: #> #> ``` #> ggsave("my_histogram.png", my_plot) #> ``` #> #> Here, we're saving the histogram as a PNG file named "my_histogram.png". You can specify the path where you want to save the file, and adjust the height and width using the `width` and `height` arguments. #> #> Hope this helps! Error Explanation One thing that endlessly frustrated me when I first learned R were the sometimes rather cryptic error messages. askgpt solved this problem by logging your errors and sending them to the OpenAI API when prompted. This works by default for tidyverse errors, but you need to enable logging first for other error messages: log_init() mean[1] askgpt("What is wrong with my last command?") #> The error message "object of type 'closure' is not subsettable" occurs when you try to subset or extract a portion of an R function or a closure object, which is not allowed. #> #> For example, if you try to index a function by using the `[ ]` operator, the error message will appear. This is because functions are not indexable or subsettable objects in R. #> #> Here's an example code that produces this error: #> #> ```r #> # defining a function #> myFun x^2 #> } #> #> # trying to subset the function with index #> myFun[1:3] #> ``` #> #> When you run this code, you'll get the error message: #> #> ``` #> Error in myFun[1:3] : object of type 'closure' is not subsettable #> ``` #> #> The error message is telling you that you can't subset the `myFun` function since it is not a data object with indexable elements. #> #> To fix this error, you need to make sure that you are not trying to subset or extract a portion of a function or closure object. Instead, you should use the function or closure as it was intended to be used. If you want to extract some value or output from the function, you can assign it to a variable or use it as an argument in another function call. “What is wrong with my last command?” in this case is a special trigger that sends your last error message and the code that produced it. "help!" is a short alias and does the same thing. Addin for Teaching The package also comes with several RStudio addins that solve some common functions for leaning or teaching R and for developing packages. The biggest one is the Tutorialise adding. Let’s say, you have the code for a tutorial ready and a general plan on how to proceed. Now the final step is to make this into a class with explanations for the code and some examples. Highlight the code and select Tutorialise Code from the Addins menu: Other Addins At the moment, there are four more addins. 2 targeted at people learning R, two for R developers: Explain Code sends the highlighted code to the API and returns the answer in the Console Annotate Code adds comments to the highlighted code directly in the R script Document Code documents functions using roxygen2 syntax Write Test creates a testthat style unit test for a highlighted function Configuration You can configure how askgpt sends API requests by using options that start with askgpt_*. For example, to use a different model to use in askgpt() use options(askgpt_chat_model = "gpt-3.5-turbo-0301"). If you use the completions instead of the chat API (chat = FALSE in askgpt()) use options(askgpt_completions_model = "text-curie-001"). It does not matter if the API parameter is listed in the function or not. All are used. See the complete list here and here. The most important setting, however, is askgpt_config. This can be used to configure the chat using plain English: options(askgpt_config = "I'm 8 years old, please explain things easily") askgpt("What is an R function?") #> #> ── Answer ────────────────────────────────────────────────────────────────────── #> An R function is like giving your friend a set of instructions to perform a #> particular task. In R programming, a function is a set of instructions or steps #> that is given a name, and when you call that name, the function will perform #> those instructions. A function can take information or inputs, do something #> with those inputs (like adding or subtracting), and then give the result back #> as output. #> #> For example, think about giving your friend the instructions to make a peanut #> butter sandwich. The instructions might be: #> #> 1. Take two slices of bread 2. Spread peanut butter on one slice 3. Spread #> jelly on the other slice 4. Put the two slices together #> #> In R, a function might take a number (like 5) and add 1 to it, and then return #> the result (which would be 6). #> #> Functions in R are used to make code easier to use, understand, and reuse. They #> can also help programmers write complex and efficient programs. Technical Details on the Conversation History One more rather technical detail about the package is that the conversation history is not kept locally (I mean OpenAI is definitly storing your requests somewhere, but it is not used inside the conversation). Rather, the questions and answers are stored in the R environment. You can access it using the function prompt_history() and response_history(): prompt_history() #> [1] "Can you explain how functions work in R?" #> [2] "How do you make a histogram with ggplot2?" #> [3] "I don't understand what you mean. Can you explain this for beginners?" #> [4] "explain why this R code does not work:\nNULL\n\"object of type 'closure' is not subsettable\"" response_history() #> [1] "Yes, of course! \n\nFunctions in R are like self-contained units of code that perform a specific task. They are used to create reusable code to avoid writing the same task again and again. In R, we use pre-defined inbuilt functions or we create our own functions as per our requirement. \n\nHere's how a simple function works in R:\n\n```r\n# Creating a function:\nmy_function
Scientists' Perspectives on the Potential for Generative AI in their Fields
Generative AI models, including large language models and multimodal models that include text and other media, are on the cusp of transforming many aspects of modern life, including entertainment, education, civic life, the arts, and a range of professions. There is potential for Generative AI to have a substantive impact on the methods and pace of discovery for a range of scientific disciplines. We interviewed twenty scientists from a range of fields (including the physical, life, and social sciences) to gain insight into whether or how Generative AI technologies might add value to the practice of their respective disciplines, including not only ways in which AI might accelerate scientific discovery (i.e., research), but also other aspects of their profession, including the education of future scholars and the communication of scientific findings. In addition to identifying opportunities for Generative AI to augment scientists' current practices, we also asked participants to reflect on concerns about AI. These findings can help guide the responsible development of models and interfaces for scientific education, inquiry, and communication.
In-situ Model Downloading to Realize Versatile Edge AI in 6G Mobile Networks
Huang, Kaibin, Wu, Hai, Liu, Zhiyan, Qi, Xiaojuan
The sixth-generation (6G) mobile networks are expected to feature the ubiquitous deployment of machine learning and AI algorithms at the network edge. With rapid advancements in edge AI, the time has come to realize intelligence downloading onto edge devices (e.g., smartphones and sensors). To materialize this version, we propose a novel technology in this article, called in-situ model downloading, that aims to achieve transparent and real-time replacement of on-device AI models by downloading from an AI library in the network. Its distinctive feature is the adaptation of downloading to time-varying situations (e.g., application, location, and time), devices' heterogeneous storage-and-computing capacities, and channel states. A key component of the presented framework is a set of techniques that dynamically compress a downloaded model at the depth-level, parameter-level, or bit-level to support adaptive model downloading. We further propose a virtualized 6G network architecture customized for deploying in-situ model downloading with the key feature of a three-tier (edge, local, and central) AI library. Furthermore, experiments are conducted to quantify 6G connectivity requirements and research opportunities pertaining to the proposed technology are discussed.
When Crowd Meets Persona: Creating a Large-Scale Open-Domain Persona Dialogue Corpus
Cho, Won Ik, Lee, Yoon Kyung, Bae, Seoyeon, Kim, Jihwan, Park, Sangah, Kim, Moosung, Hahn, Sowon, Kim, Nam Soo
Building a natural language dataset requires caution since word semantics is vulnerable to subtle text change or the definition of the annotated concept. Such a tendency can be seen in generative tasks like question-answering and dialogue generation and also in tasks that create a categorization-based corpus, like topic classification or sentiment analysis. Open-domain conversations involve two or more crowdworkers freely conversing about any topic, and collecting such data is particularly difficult for two reasons: 1) the dataset should be ``crafted" rather than ``obtained" due to privacy concerns, and 2) paid creation of such dialogues may differ from how crowdworkers behave in real-world settings. In this study, we tackle these issues when creating a large-scale open-domain persona dialogue corpus, where persona implies that the conversation is performed by several actors with a fixed persona and user-side workers from an unspecified crowd.
Accelerating Wireless Federated Learning via Nesterov's Momentum and Distributed Principle Component Analysis
Dong, Yanjie, Wang, Luya, Chi, Yuanfang, Wang, Jia, Zhang, Haijun, Yu, Fei Richard, Leung, Victor C. M., Hu, Xiping
A wireless federated learning system is investigated by allowing a server and workers to exchange uncoded information via orthogonal wireless channels. Since the workers frequently upload local gradients to the server via bandwidth-limited channels, the uplink transmission from the workers to the server becomes a communication bottleneck. Therefore, a one-shot distributed principle component analysis (PCA) is leveraged to reduce the dimension of uploaded gradients such that the communication bottleneck is relieved. A PCA-based wireless federated learning (PCA-WFL) algorithm and its accelerated version (i.e., PCA-AWFL) are proposed based on the low-dimensional gradients and the Nesterov's momentum. For the non-convex loss functions, a finite-time analysis is performed to quantify the impacts of system hyper-parameters on the convergence of the PCA-WFL and PCA-AWFL algorithms. The PCA-AWFL algorithm is theoretically certified to converge faster than the PCA-WFL algorithm. Besides, the convergence rates of PCA-WFL and PCA-AWFL algorithms quantitatively reveal the linear speedup with respect to the number of workers over the vanilla gradient descent algorithm. Numerical results are used to demonstrate the improved convergence rates of the proposed PCA-WFL and PCA-AWFL algorithms over the benchmarks.
Masked Vision-language Transformer in Fashion - Machine Intelligence Research
Work was done while Ge-Peng Ji was a research intern at Alibaba Group. The authors declared that they have no conflicts of interest in this work. We declare that we do not have any commercial or associative interest that represents a conflict of interest in connection with the work submitted. Ge-Peng Ji received the M. Sc. degree in communication and information systems from Wuhan University, China in 2021. He is currently a Ph.D. degree candidate at Australian National University, supervised by Professor Nick Barnes, majoring in engineering and computer science.
Can ChatGPT be used to generate scientific hypotheses?
Park, Yang Jeong, Kaplan, Daniel, Ren, Zhichu, Hsu, Chia-Wei, Li, Changhao, Xu, Haowei, Li, Sipei, Li, Ju
We investigate whether large language models can perform the creative hypothesis generation that human researchers regularly do. While the error rate is high, generative AI seems to be able to effectively structure vast amounts of scientific knowledge and provide interesting and testable hypotheses. The future scientific enterprise may include synergistic efforts with a swarm of "hypothesis machines", challenged by automated experimentation and adversarial peer reviews. In a university or research institute, a significant portion of fresh ideas arises out of discussions.
Milestones in Autonomous Driving and Intelligent Vehicles: Survey of Surveys
Chen, Long, Li, Yuchen, Huang, Chao, Li, Bai, Xing, Yang, Tian, Daxin, Li, Li, Hu, Zhongxu, Na, Xiaoxiang, Li, Zixuan, Teng, Siyu, Lv, Chen, Wang, Jinjun, Cao, Dongpu, Zheng, Nanning, Wang, Fei-Yue
Interest in autonomous driving (AD) and intelligent vehicles (IVs) is growing at a rapid pace due to the convenience, safety, and economic benefits. Although a number of surveys have reviewed research achievements in this field, they are still limited in specific tasks, lack of systematic summary and research directions in the future. Here we propose a Survey of Surveys (SoS) for total technologies of AD and IVs that reviews the history, summarizes the milestones, and provides the perspectives, ethics, and future research directions. To our knowledge, this article is the first SoS with milestones in AD and IVs, which constitutes our complete research work together with two other technical surveys. We anticipate that this article will bring novel and diverse insights to researchers and abecedarians, and serve as a bridge between past and future.
Questions of science: chatting with ChatGPT about complex systems
Crokidakis, Nuno, de Menezes, Marcio Argollo, Cajueiro, Daniel O.
We are currently in a great era for researchers and scientists studying and developing in the field of complex systems. Half of the physics Nobel prize of 2021 was awarded to the physicist Giorgio Parisi for his contributions to the theory of complex systems [9] and the other half to two meteorologists Syukuro Manabe and Klaus Hasselmann to the modeling of the Earth's climate [10]. Parisi has made significant contributions to the literature on complex systems, including areas such as spin glass [11, 12, 13], stochastic resonance [14], surface growth [15], multifractality [16], and bird flocking [17].
All the Risks Tesla Is Willing to Take to Deliver on Self-Driving
There's a whole genre of YouTube videos of people showing how their Teslas can drive themselves around. These users are testing out Tesla's Full Self-Driving capabilities--which sometimes work great, and other times … not so much. Most of these videos are made by true believers who want the company to succeed but are also honest when the tech fails and Tesla's promises fall short. These promises, after all, are big--and have long come directly from Elon Musk. But so are the risks: Last month, Tesla recalled around 360,000 cars with the company's Full Self-Driving beta system--which, in this case, meant the company had to push a software update to address behavior that increased the risk of a crash, like exceeding speed limits or traveling through intersections, according to a government regulator.