
---
title: "Text embedding dataset with riken pressrelease text (Japanese)"
author:
  - name: Satoshi Kume
date: "`r Sys.Date()`"
graphics: no
package: chatAI4R
output:
  BiocStyle::html_document:
  toc_float: true
vignette: >
  %\VignetteEncoding{UTF-8}
  %\VignetteDepends{chatAI4R}
  %\VignetteIndexEntry{Text embedding dataset with riken pressrelease text (Japanese)}
  %\VignetteEngine{knitr::rmarkdown}
editor_options: 
  chunk_output_type: console
---

```{r style, echo = FALSE, results = 'asis', message=FALSE}
BiocStyle::markdown()
```

**Last modified:** `r file.info("riken_pressrelease_text_jpn.Rmd")$mtime`<br>
**Compiled**: `r Sys.time()`

# Introduction

The advent of Large Language Models (LLM) has significantly advanced the resolution of general challenges that were previously anticipated in the field of natural language processing. An LLM is a type of AI that learns from a vast amount of text data, enabling it to understand and generate natural language. Its capabilities have found applications in various areas, such as question-answering systems and text generation tools.

Moreover, LLMs have allowed natural language to serve as a prompt, enabling us to give instructions to Artificial Intelligence (AI). This development has blurred the boundary between natural language and computer language in the context of AI, creating a new paradigm where both hold equivalent meanings.

However, there are still challenges when it comes to specialized language models. For instance, the accuracy of LLMs is not as high in specific areas, such as highly specialized documents in fields like medicine or law, niche sectors, or materials published exclusively by certain institutions.

In this study, we attempted to construct a specialized language model based on structured, specialized documents. Specifically, we focused on press release articles from RIKEN. These articles, which summarize RIKEN's research achievements, are created based on certain standards, making them semi-structured text data.

Our first step was to create a dataset based on these articles. We broke down each article into titles and specialized texts, performed text embedding to convert each text into vector space. From there, we extracted specialized knowledge and context related to specific research fields and used this information to train the specialized language model. In essence, we provided these as prompts to the LLM, and by fine-tuning the model as needed, we expected to improve its accuracy.

This initiative opens up new possibilities in the field of AI and natural language processing. It holds the potential to significantly enhance the accuracy and efficiency of information processing in areas that require specialized knowledge.


# Collect URLs

```{r echo=TRUE, eval=FALSE}
#Bio
urls1 <- c("https://www.riken.jp/press/2020/20200120_2/",
          "https://www.riken.jp/press/2023/20230606_1/index.html",
          "https://www.riken.jp/press/2023/20230126_1/index.html",
          "https://www.riken.jp/press/2023/20230130_2/index.html",
          "https://www.riken.jp/press/2017/20170427_1/index.html")

#Pysics
urls2 <- c("https://www.riken.jp/press/2023/20230321_1/index.html",
           "https://www.riken.jp/press/2023/20230120_1/index.html")

#combine
urls <- c(urls1, urls2)
```

# text embedding for press release 

You should always check your API key.

```{r echo=TRUE, eval=FALSE}
dataset <- list()
#api_key <- "your API key"

#perform text embedding
for(n in 1:length(urls)){
  cat(n)
  dataset[[n]] <- riken_pressrelease_textEmbedding(urls[n], api_key)
  cat(" ")
}
```

#MDS for press release tittles

```{r echo=TRUE, eval=FALSE}
dat1 <- c()
for(k in 1:length(dataset)){
  dat1 <- rbind(dat1, dataset[[k]][1,])
}

#mds
mds_result <- cmdscale(dist(dat1[,-1]), k = 2)

#plot
par(family = "HiraKakuPro-W3")
plot(mds_result, 
     xlab = "Dimension 1", ylab = "Dimension 2", 
     main = "MDS Result", 
     type = "p")
text(mds_result, 
     labels = sapply(dat1[,1], function(x) paste(strwrap(x, width = 20), collapse = "\n")), 
     cex=0.25)
```

#MDS for main text

```{r echo=TRUE, eval=FALSE}
dat2 <- c()
for(k in 1:length(dataset)){
  d <- data.frame(NO=k, 
                  textNO=2:nrow(dataset[[k]]), 
                  dataset[[k]][-1,])
  dat2 <- rbind(dat2, d)
}

#mds
mds_result <- cmdscale(dist(dat2[,-c(1:3)]), k = 2)

#plot
par(family = "HiraKakuPro-W3")
plot(mds_result, 
     xlab = "Dimension 1", ylab = "Dimension 2", 
     main = "MDS Result", 
     type = "p", pch=21, 
     bg=rainbow(max(dat2$NO), alpha = 0.7)[dat2$NO], cex=1.25)
text(mds_result, 
     labels = paste0(dat2$NO, "-", dat2$textNO), 
     cex=0.4)

#出力
print(dat1[,1])
table(dat2$NO)

dat2[dat2$NO == 1,3]
dat2[dat2$NO == 2,3]
dat2[dat2$NO == 3,3]
dat2[dat2$NO == 4,3]
dat2[dat2$NO == 5,3]
dat2[dat2$NO == 6,3]
dat2[dat2$NO == 7,3]
```

#

```{r}
questions <- "音楽を聞いている時の気分変化から自律神経機能を予測できますか？"





```




# Session information {.unnumbered}
```{r sessionInfo, echo=TRUE}
sessionInfo()
```
