\section{Introduction}
As natural language understanding of sentences and short documents continues to improve, there has been growing interest in tackling longer-form documents such as academic papers \citep{Ren2014,Bhagavatula2018}, novels \citep{Iyyer2016} and screenplays \citep{Gorinski2018}.
Analyses of such documents can take place at multiple levels, e.g. identifying both document-level labels (such as genre), as well as narrative trajectories (how do levels of humor and romance vary over the course of a romantic comedy?).
However, one of the key challenges for these tasks is that the signal-to-noise ratio over lengthy texts is generally low (as indicated by the performance of such models on curated datasets like NarrativeQA \citep{Kocisky2018}), making it difficult to apply end-to-end neural network solutions that have recently achieved state-of-the-art on other tasks \citep{Barrault2019,Williams2018,Wang2019}.

Instead, models either rely on a) a \emph{pipeline} that provides a battery of syntactic and semantic information from which to craft features (e.g., the BookNLP pipeline \citep{Bamman2014} for literary text, graph-based features \citep{Gorinski2015} for movie scripts, or outputs from a discourse parser \citep{Ji2017} for text categorization) and/or b) the \emph{linguistic intuitions} of the model designer to select features relevant to the task at hand (e.g., rather than ingesting the entire text, \citet{Bhagavatula2018} only consider certain subsections like the title and abstract of an academic publication).
While there is much to recommend these approaches, end-to-end neural modeling offers several key advantages: in particular, it obviates the need for auxiliary feature-generating models, minimizes the risk of error propagation, and offers improved generalization across large-scale corpora.
This work explores how models can leverage the inherent structure of a document class to facilitate an end-to-end approach.
Here, we focus on screenplays, investigating whether we can effectively extract key information by first segmenting them into scenes, and then further exploiting the structural regularities within each scene.

With an average of \textgreater 20k tokens per script in our evaluation corpus, extracting salient aspects is far from trivial.
Through a series of carefully controlled experiments, we show that a structure-aware approach significantly improves document classification by effectively collating sparsely distributed information.
Further, this method produces both document- and scene-level embeddings, which can be used downstream to visualize narrative trajectories of interest (e.g., the prominence of various themes across the script).
The overarching strategy of this work is to incorporate structural priors as biases into the \emph{architecture} of the neural network model itself (e.g., \citet{Socher2013}, \citet{Strubell2018}, \emph{inter alia}).
The methods we propose can readily generalize to any long-form text with an exploitable internal structure, including novels (chapters), theatrical plays (scenes), chat logs (turn-taking), online games (levels/rounds/gameplay events), and academic texts (sections and subsections).

The paper is organized as follows: In \S\ref{sec:script_structure}, we detail how a script can be formally decomposed into scenes, and each scene can be further decomposed into granular elements with distinct discourse functions. \S\ref{sec:hse} elaborates on how this structure can be effectively leveraged with a proposed encoder based on hierarchical attention \citep{Yang2016}. In \S\ref{sec:tag_prediction}, the predictive performance of the hierarchical encoder is validated on two multi-label tag prediction tasks, one of which rigorously establishes the utility of modeling structure at multiple granularities (i.e., at the level of line, scene, and script).
Notably, while the resulting scene-encoded representation is useful for prediction tasks, it is not amenable to easy interpretation or examination.
To shed further light on encoded document representation, in \S\ref{sec:unsup_dict_learn}, we propose an unsupervised interpretability module that can be attached to an encoder of any complexity.
\S\ref{sec:qual_analysis} outlines our application of this module to the scene encoder, and the resulting visualizations of the screenplay, which neatly illustrate how plot elements vary over the course of the narrative arc.
\S\ref{sec:related} draws connections to related work, before concluding.

\section{Script Structure}
\label{sec:script_structure}
\begin{figure}[!t]
    \begin{center}
        \includegraphics[height=0.15\textheight, width=0.9\textwidth]{./pulp_fiction_scene.pdf}
    \end{center}
    \caption{A portion of the screenplay for \emph{Pulp Fiction}, annotated with the common scene components.}
    \vspace{-0.3cm}
    \label{fig:example_screenplay}
\end{figure}
Movie and television scripts, also known as screenplays, are traditionally segmented into \emph{scenes}, with a rough rule of thumb that each scene lasts about a minute on-screen.
A scene is not necessarily a distinct narrative unit (which are most often sequences of several consecutive scenes), but is constituted by a piece of continuous action at a single location
\begin{table}[!h]
    \begin{center}
    \scriptsize
    \begin{tabular}{p{1.2cm}p{12pt}p{12pt}p{0.5cm}p{1cm}p{1.8cm}}
        Title& Line& Scene& Type& Character& Text \\\hline
        Pulp Fiction& 204& 4& Scene & & {EXT. APART..} \\
        Pulp Fiction& 205& 4& Action & & {Vincent and Jules.} \\
        Pulp Fiction& 206& 4& Action & & {We TRACK...} \\
        Pulp Fiction& 207& 4& Dial. & VINCENT & What's her name?\\
        Pulp Fiction& 208& 4& Dial. & JULES & Mia. \\
        Pulp Fiction& 209& 4& Dial. & VINCENT & How did... \\
    \end{tabular}
    \end{center}
    \vspace{-0.3cm}
\caption{Post-processed version of Fig.\ref{fig:example_screenplay}.}
\label{tab:processed_script}
\end{table}

Fig. \ref{fig:example_screenplay} contains a segment of a scene from the screenplay for the movie \emph{Pulp Fiction}, a 1994 American film.
These segments tend to follow a standard format.
Each scene starts with a scene heading or ``slug line" that briefly describes the scene setting, followed by a sequence of statements.
Screenwriters typically use formatting to distinguish between dialogue and action statements \citep{Argentini1998}.
The first kind contains lines of a dialogue and identifies the character who utters it either on- or off-screen (the latter is often indicated with `(V.O.)' for voice-over).
Occasionally, parentheticals are used to include special instructions for how an utterance should be delivered by the character.
Action statements, on the other hand, are all non-dialogue constituents of the screenplay ``often used by the screenwriter to describe character actions, camera movement, appearance, and other details" \citep{Pavel2015}.
In this work, we consider action and dialogue statements, as well as character identities for each dialogue segment, and ignore slug lines and parentheticals.

\section{Hierarchical Scene Encoders}
\label{sec:hse}
Given the size of a movie script, it is computationally infeasible to treat these screenplays as single blocks of text to be ingested by a recurrent encoder.
Instead, we propose a hierarchical encoder that mirrors the standard structure of a screenplay (\S\ref{sec:script_structure}) -- a sequence of scenes, each of which is in turn an interwoven sequence of action and dialogue statements.
The encoder is three-tiered, as illustrated in Fig. \ref{fig:model_schematic} and processes the text of a script as follows.

\subsection{Model Architecture}
\label{sec:model_architecture}
First, an \textbf{action-statement encoder} transforms the sequence of words in an action statement (represented by their pretrained word embeddings) into an action statement embedding.
Next, an \textbf{action-scene encoder} transforms the chronological sequence of action statement embeddings within a scene into an action scene embedding.
Analogously, a \textbf{dialogue-statement encoder} and a \textbf{dialogue-scene encoder} are used to obtain dialogue statement embeddings and aggregate them into dialogue scene embeddings.
To evaluate the effect of character information, characters with at least one dialogue statement in a given scene are represented by an individual character embedding (these are randomly initialized and estimated during model training), and a scene-level character embedding is constructed by averaging the embeddings of all the characters in the scene\footnote{We only take into account characters at the \emph{scene} level i.e., we do not associate characters with each dialogue statement, leaving this addition to future work.}.
Finally, the action, dialogue and scene-level character embeddings for each scene are concatenated into a single scene embedding.
\begin{figure}[!htbp]

    \begin{center}
        \includegraphics[width=0.9\textwidth,keepaspectratio,trim={0 3.5cm 11.5cm 0.5cm}]{./model_schematic.pdf}
    \end{center}

    \caption{The architecture of our script encoder, largely following the structure in Fig. \ref{fig:example_screenplay}.}
    \label{fig:model_schematic}
\end{figure}
\vspace{-0.25cm}

Scene-level predictions or analyses can then be obtained by feeding the scene embeddings into a subsequent module of the neural architecture, e.g. a feedforward layer can be used for supervised tagging tasks.
Alternatively, if a single representation of the entire screenplay is required, a final \textbf{script encoder} is used to transform the sequence of scene embeddings for a script into a single script embedding.
A key assumption underlying the model is that action and dialogue statements -- as instances of written narrative and spoken language respectively -- are distinct categories of text and must therefore be processed separately.
We evaluate this assumption in the tag classification experiments (\S\ref{sec:tag_prediction}).

\subsection{Encoders}
\label{sec:encoders}
The proposed model incorporates strong inductive biases regarding the overall structure of input documents.
In addition, each of the aforementioned encoders in \S\ref{sec:model_architecture} can be specified in multiple ways, and we evaluate three different instantiations of the encoder components:
\begin{enumerate}
    \item \textbf{Sequential (GRU):} A bidirectional GRU \citep{Bahdanau2015} is used to encode the temporal sequence of inputs (of words, statements or scenes).
    Given a sequence of input embeddings $\mathbf{e}_1, \dots, \mathbf{e}_T$ for a sequence of length $T$, we obtain GRU outputs $\mathbf{c}_1, \dots, \mathbf{c}_T$, and use $\mathbf{c}_T$ as the recurrent encoder's final output.

    Other sequential encoders could also be used as alternatives.
    \item \textbf{Sequential with Attention (GRU + Attn):} Attention \citep{Bahdanau2015} can be used to combine sequential outputs $\mathbf{c}_1, \dots, \mathbf{c}_T$, providing a mechanism for more or less informative inputs to be filtered accordingly.
    We calculate attention weights using a parametrized vector $\mathbf{p}$ of the same dimensionality as the GRU outputs \citep{Sukhbaatar2015,Yang2016}:
    \begin{align*}
        \alpha_i = \frac{\mathbf{p}^T \mathbf{c}_i}{\Sigma_{j=1}^{T}\mathbf{p}^T \mathbf{c}_j}
    \end{align*}
    These weights are used to compute the final output of the encoder as:
    \begin{align*}
        \mathbf{c} = \Sigma_{j=1}^{T} \alpha_i \mathbf{c}_i
    \end{align*}
    Other encoders with attention could be used as alternatives to this formulation.
    \item \textbf{Bag-of-Embeddings with Attention (BoE + Attn):} Another option is to disregard the sequential encoding and simply compute an attention-weighted average of the inputs to the encoder as follows:
    \begin{align*}
        \alpha_i &= \frac{\mathbf{p}^T \mathbf{e}_i}{\Sigma_{j=1}^{T}\mathbf{p}^T \mathbf{e}_j}\\
         \mathbf{c} &= \Sigma_{j=1}^{T} \alpha_i \mathbf{e}_i
    \end{align*}
    This encoder stands in contrast to a bag-of-embeddings (BoE) encoder which computes a simple average of its inputs.
    While defining a far more constrained function space than recurrent encoders, BoE and BoE + Attn representations have the advantage of being interpretable (in the sense that the encoder's output is in the same space as the input word embeddings).
    We leverage this property in \S\ref{sec:unsup_dict_learn} where we develop an interpretability layer on top of the encoder outputs.
\end{enumerate}

\subsection{Loss for Tag Classification}
\label{sec:classifier_loss}
The final script embedding being passed into a feedforward classifier (FFNN).
As both supervised learning tasks in our evaluation are multi-label classification problems, we use a variant of a simple multi-label one-versus-rest loss, where correlations among tags are ignored.
The tag sets have high cardinalities and the fractions of positive samples are inconsistent across tags (Table \ref{tab:tag_cardinality} in \ref{sec:add_stats}); this motivates us to train the model with a reweighted loss function:
\begin{align}
L(y,z) &= \tfrac{1}{NL} \Sigma_{i=1}^{N} \Sigma_{j=1}^{L} y_{ij} \log\sigma(z_{ij}) \nonumber \\
    &+ \lambda_j (1 - y_{ij}) (1 - \log\sigma(z_{ij})) \label{eq:loss_fn}
\end{align}
where $N$ is the number of samples, $L$ is the number of tag labels, $y \in \{0, 1\}$ is the tag label, $z$ is the output of the FFNN, $\sigma$ is the sigmoid function, and $\lambda_j$ is the ratio of positive to negative samples (precomputed over the entire training set, since the development set is too small to tune this parameter) for the tag label indexed by $j$.
With this loss function, we account for label imbalance without using separate thresholds for each tag tuned on the validation set.

\section{Interpreting Scene Embeddings}
\label{sec:unsup_dict_learn}
As the complexity of learning methods used to encode sentences and documents has increased, so has the need to understand the properties of the encoded representations.
Probing-based methods \citep{Linzen2016, Conneau2018} are used to gauge the information captured in an embedding by evaluating its performance on downstream classification tasks, either with manually collected annotations \citep{Shi2016} or carefully selected self-supervised proxies \citep{Adi2016}.
In our case, it is laborious and expensive to collect such annotations at the scene level (requiring domain experts), and the proxy evaluation tasks proposed in the literature do not probe the narrative properties we wish to surface.

Instead, we take inspiration from \citet{Iyyer2016} and learn a \textbf{scene descriptor model} that can be trained without relying on any such annotations.
Using a dictionary learning perspective \citep{Olshausen1997}, the model learns to represent each scene embedding as a weighted mixture of various topics estimated over the entire corpus.
It thus acts as an ``interpretability layer" that can be applied over the scene encoder.
This model class is similar in spirit to dynamic topic models \citep{Blei2006}, with the added advantage of producing topics that are both more coherent and more interpretable than those generated by LDA \citep{He2017unsupervised,Mitcheltree2018}.

\subsection{Scene Descriptor Model}
The model has three main components: a \textbf{scene encoder}, a set of topics or \textbf{descriptors} that form the ``basis elements" used to describe an interpretable scene, and a \textbf{predictor} that predicts weights over descriptors for a given scene embedding.
The scene encoder uses the text of a given scene $s_t$ to produce a corresponding scene embedding $\mathbf{v}_t$.
This encoder can take any form -- from an extractor that derives a hand-crafted feature set from the scene text, as in \citet{Gorinski2018}, to an instantiation of the scene encoder in \S\ref{sec:hse}.

\vspace{-0.25cm}
\begin{figure}[!htbp]
    \begin{center}
        \includegraphics[width=0.75\textwidth,keepaspectratio,trim={1cm 0 6cm 0}]{./descriptors_schematic.pdf}
    \end{center}
    \caption{A pictorial representation of the scene descriptor model.}
    \label{fig:descriptor_schematic}
\end{figure}
\vspace{-0.3cm}
To probe the contents of scene embedding $\mathbf{v}_t$, we compute the descriptor-based representation $\mathbf{w}_t \in \mathbb{R}^d$ in terms of a descriptor matrix $\mathbf{R}^{k \times d}$, where $k$ is the number of topics or descriptors:
\begin{align}
    \mathbf{o}_t &= \textrm{softmax}(f(\mathbf{v}_t)) \label{eq:predictor} \\
    \mathbf{w}_t &= \mathbf{R}^T \mathbf{o}_t \nonumber
\end{align}
where $\mathbf{o}_t \in \mathbb{R}^k$ is the weight (probability) vector over $k$ descriptors and $f(\mathbf{v}_t)$ is a predictor (illustrated by the leftmost pipeline in  Fig. \ref{fig:descriptor_schematic}) which converts $\mathbf{v}_t$ into $\mathbf{o}_t$.
Two variants are $f = \textrm{FFNN}(\mathbf{v}_t)$ and $f = \textrm{FFNN}([\mathbf{v}_t; \mathbf{o}_{t-1}])$ (concatenation); we use the former in \S\ref{sec:qual_analysis}.
Furthermore, we can incorporate additional recurrence into the model by modifying Eq. \ref{eq:predictor} to add the previous state:
\begin{align}
    \mathbf{o}_t = (1-\alpha)\cdot\textrm{FFNN}([\mathbf{v}_t; \mathbf{o}_{t-1}]) + \alpha\cdot\mathbf{o}_{t-1} \label{eq:recurrent_predictor}
\end{align}

\subsection{Reconstruction Task}
We wish to minimize the reconstruction error between two scene representations: (1) the descriptor-based embedding $\mathbf{w}_t$ which depends on the scene embedding $\mathbf{v}_t$, and (2) an attention-weighted bag-of-words embedding for $s_t$.
This ensures that the computed descriptor weights are indicative of the scene's actual content (specifically portions of its text that indicate attributes of interest such as genre, plot, and mood).
We use a \texttt{BoE+Attn} scene encoder (\S\ref{sec:encoders}) pretrained on the tag classification task (bottom right of Fig. \ref{fig:descriptor_schematic}), which yields a vector $\mathbf{u}_t \in \mathbb{R}^d$ for scene $s_t$.
The scene descriptor model is then trained using a hinge loss objective \citep{Weston2011} to minimize the reconstruction error  between $\mathbf{w_t}$ and $\mathbf{u}_t$, with an additional orthogonality constraint on $\mathbf{R}$ to encourage semantically distinct descriptors:
\begin{equation}
   L = \Sigma_{j=1}^{n} \max(0, 1 - \mathbf{w}_t^T \mathbf{u}_t + \mathbf{w}_t^T \mathbf{u}_j ) + \lambda \| \mathbf{RR}^T - \mathbf{I} \|_2
\end{equation}
where $\mathbf{u}_1 \dots \mathbf{u}_n$ are $n$ negative samples selected from other scenes in the same screenplay.

The motivation for using the output of a \texttt{BoE+Attn} scene encoder is that $\mathbf{w}_t$ (and therefore the rows in $\mathbf{R}$) lies in the same space as the input word embeddings.
Thus, a given descriptor can be semantically interpreted by querying in the word embedding space
The predicted descriptor weights for a scene $s_t$ can be obtained by running a forward pass through the model.

\section{Evaluation}
\label{sec:evaluation}
We evaluate the proposed script encoder architecture and its variants through two supervised multi-label tag prediction tasks, and a qualitative analysis based on extracting descriptor trajectories in an unsupervised setting.

\subsection{Datasets}
\label{sec:datasets}
Our evaluation is based on the ScriptBase-J corpus, released by \citet{Gorinski2018}.\footnote{https://github.com/EdinburghNLP/scriptbase}
In this corpus, each movie is associated with a set of expert-curated tags that range across 6 tag attributes: mood, plot, genre, attitude, place, and flag (\ref{tab:tag_examples}); in addition to evaluating on these tags, we also used an internal dataset, where the same movies were hand-labeled by in-house domain experts across 3 tag attributes: genre, plot, and mood.
The tag taxonomies between these two datasets are distinct (Table \ref{tab:tag_cardinality}).
ScriptBase-J was used both to directly compare our approach with an implementation of the multilabel encoder architecture in \citet{Gorinski2018} and to provide an open-source evaluation standard.

\subsubsection*{Script Preprocessing}
As in \citet{Pavel2015}, we leveraged the standard screenplay format \citep{Argentini1998} to extract a structured representation of the scripts (relevant formatting cues included capitalization and tab-spacing; see Fig. \ref{fig:example_screenplay} and Table \ref{tab:processed_script} for an example).
Filtering erroneously processed scripts removed 6\% of the corpus, resulting in 857 scripts total.
We set aside 20\% (172 scripts) for heldout evaluation; the remainder was used for training.
The average number of tokens per script is around 23k; additional statistics are shown in Table \ref{tab:token_stats}.

Next, we split extremely long scenes into smaller ones, capping the maximum number of lines in a scene (across both action and dialogue) to 60 (keeping within GPU memory limits).
For the vocabulary, a word count of 5 across the script corpus was set as the minimum threshold.
The number of samples (scripts) per tag value ranges from high (e.g., for some genre tags) to low (for most plot and mood tags) in both datasets (\S\ref{sec:add_stats}), and coupled with high tag cardinality for each attribute, motivates the need for the reweighted loss in Eq.~\ref{eq:loss_fn}.

\subsection{Experimental Setup}
All inputs to the hierarchical scene encoder are 100-dimensional GloVe embeddings \cite{Pennington2014}.\footnote{Using richer contextual word representations will improve performance, but is orthogonal to the purpose of this work.}
Our sequential models are  biGRUs with a single 50-dimensional hidden layer in each direction, resulting in 100-dimensional outputs.
The attention model is parametrized by a 100-dimensional vector $\mathbf{p}$; BoE models naturally output 100-dimensional representations, and character embeddings are 10-dimensional.
The output of the script encoder is passed through a linear layer with a sigmoid activation function and binarized by thresholding at 0.5.

One simplification in our experiments is to utilize the same encoder \emph{type} for all encoders described in \S\ref{sec:model_architecture}.
However, it is conceivable that different encoder types might perform better at different tiers of the architecture: e.g. scene aggregation can be done in a permutation-invariant manner, since narratives are interwoven and scenes may not be truly sequential.

We implement the script encoder on top of AllenNLP \citep{Gardner2017} and PyTorch \citep{Paszke2019}, and all experiments were conducted on an AWS \texttt{p2.8xlarge} machine.
We use the Adam optimizer with an initial learning rate of $5e^{-3}$, clip gradients at a maximum norm of 5, and do not use dropout.
The model is trained for a maximum of 20 epochs to maximize average precision score, and with early stopping in place if the validation metric does not improve for 5 epochs.

\subsection{Tag Prediction Experiments}
\label{sec:tag_prediction}
ScriptBase-J also comes with ``loglines", or short, 1-2 sentence human-crafted summaries of the movie's plot and mood (see Table \ref{tab:tag_examples}).
A model trained on these summaries can be expected to provide a reasonable baseline for tag prediction, since human summarization is likely to pick out relevant parts of the text for this task.
The loglines model is a bidirectional GRU with inputs of size 100 (GloVe embeddings) and hidden units of size 50 in each direction, whose output feeds into a linear classifier.\footnote{We tried both with and without attention and found the variant without attention to give slightly better results.}
\begin{table}[!h]
\vspace{-0.4cm}
\begin{tabular}{lrrr}
{\textbf{Model}} & {\textbf{Genre}} & {\textbf{Plot}} & {\textbf{Mood}} \\\hline
Loglines & 49.9 (0.8) & 12.7 (0.9) & 17.5 (0.2) \\
\hline
\multicolumn{4}{l}{\textit{Comparing encoder variations:}}\\
BoE & 49.0 (1.1) & 8.3 (0.6) & 12.9 (0.7) \\
BoE + Attn & 51.9 (2.3) & 11.3  (0.4) & 16.3 (0.6) \\
GRU & 57.9 (1.9) & 13.0 (1.3) & 19.1 (1.0) \\
GRU + Attn & 60.5 (2.0) & {\bf 15.2} (0.4) & {\bf 22.9} (1.4) \\
\hline
\multicolumn{4}{l}{\textit{Variants on GRU + Attn for action \& dialog:}} \\
+ Chars & {\bf 62.5} (0.7) & 11.7 (0.3) & 18.2 (0.3) \\
- Action & 60.5 (2.9) & 13.5 (1.4) & 20.0 (1.2) \\
- Dialogue & 60.5 (0.6) & 13.4 (1.7) & 19.1 (1.4) \\
2-tier & 61.3 (2.3) & 13.7 (1.7) & 20.6 (1.2) \\
HAN & 61.5 (0.6) & 14.2 (1.7) & 20.7 (1.4)
\end{tabular}
\caption{Investigation of the effects of different architectural (BoE +/- Attn, GRU +/- Attn) and structural choices on a tag prediction task, using an internally tagged dataset: F-1 scores with sample standard deviation in parentheses. Across the 3 tag attributes we find that modeling sentential and scene-level structure helps, and attention helps extract representations more salient to the task at hand.}
\label{tab:content_exps}
\vspace{-0.2cm}
\end{table}

Table \ref{tab:content_exps} contains results for the tag prediction task on our internally-tagged dataset.
First, a set of models trained using action and dialogue inputs are used to evaluate the architectural choices in \S\ref{sec:model_architecture}.
We find that modeling recurrence at the sentential and scene levels, and using attention to select relevant words or scenes, help considerably and are necessary for robust improvement over the loglines' baseline (see the first five rows in Table \ref{tab:content_exps}).

Next, we assess the effect that various structural elements of a screenplay have on classification performance. Notably, the difficulty of the prediction task is directly related to the set size of the tag attribute: higher-cardinality tag attributes with correlated tag values (like plot and mood)  are significantly more difficult to predict than lower-cardinality tags with more discriminable values (like genre).
We find that adding character information to the best-performing GRU + Attn model (\texttt{+Char}) improves prediction of genre, while using both dialogue and action statements improves performance on plot and mood, compared to using only one or the other.
We also evaluate (1) a \texttt{2-tier} variant of the \texttt{GRU+Attn} model without action/dialogue-statement encoders (i.e., all action statements are concatenated into a single sequence of words and passed into the action-scene encoder, and similarly with dialogue) and (2) a variant similar to \citet{Yang2016} (\texttt{HAN}) that does not distinguish between action and dialogue (i.e., all statements in the text of a scene are encoded using a statement encoder and statement embeddings are passed to a single scene encoder, the output of which is passed into the script encoder).
Both models perform slightly better than \texttt{GRU+Attn} on genre, but worse on plot and mood, showing that for more difficult prediction tasks, it helps to incorporate hierarchy and to distinguish action and dialogue statements.

\begin{table}[!h]
\vspace{-0.2cm}
\begin{center}
\begin{tabular}{l|rr}
\textbf{Tag} & \textbf{G\&L} & \textbf{HSE} \\
\hline
Attitude & 72.6 & 70.1 \\
Flag & 52.5 & 52.6 \\
Genre & 55.1 & 42.5 \\
Mood & 45.5 & 51.2 \\
Place & 57.7 & 29.1 \\
Plot & 34.6 & 34.5
\end{tabular}
\end{center}
\vspace{-0.4cm}
\caption{F-1 scores on ScriptBase-J provided tag set, comparing \citet{Gorinski2018}'s approach to ours.}
\label{tab:jinni}
\end{table}
For the results in Table \ref{tab:jinni}, we compared the \texttt{GRU+Attn} configuration in Table \ref{tab:content_exps} (\texttt{HSE}) with an implementation of \citet{Gorinski2018} (\texttt{G\&L}) that was run on the previous train-test split.
\texttt{G\&L} contains a number of handcrafted lexical, graph-based, and interactive features that were designed for optimal performance for screenplay analysis.
In contrast, \texttt{HSE} directly encodes standard screenplay structure into a neural network architecture, and is an alternative, arguably more lightweight way of building a domain-specific textual representation.
Our results are comparable, with the exception of ``place", which can often be identified deterministically from scene headings.

\subsection{Similarity-based F-1}
\label{sec:similarity_scoring}
Results in Tables \ref{tab:content_exps} and \ref{tab:jinni} are stated using standard multi-label F-1 score (one-vs-rest classification evaluation, micro-averaged over each tag attribute), which requires an exact match between predicted and actual tag value to be deemed correct.
However, the characteristics of our tag taxonomies suggest that this measure may not be ideal.
In particular, our human-crafted tag sets have tag attributes with dozens of highly correlated, overlapping values, as well as missing tags not assigned by the annotator.
A standard scoring procedure may underestimate model performance when, e.g., a prediction of ``Crime" for a target label of ``Heist", is counted as equivalently wrong to ``Romance" (Table \ref{tab:tag_similarity} in \ref{sec:add_stats}).

One way to deal with tag sets is to leverage a similarity-based scoring procedure (see \citet{Maynard2006} for related approaches).
Such a measure takes into account the latent relationships among tags via \emph{similarity thresholding}, wherein a prediction is counted as correct if it is within a certain distance of the target.
In particular, we treat a prediction as correct based the percentile of its similarity to the actual label.
The percentile cutoff can be varied to illustrate how estimated model performance varies as a function of the degree of ``enforced" similarity between target and prediction.

\begin{figure}[t!]
\centering
    \includegraphics[width=0.9\textwidth,keepaspectratio,trim={1cm, 1cm 0cm 0cm}]{sim_performance.png}
\caption{F1 score of various tag attributes as a function of the similarity threshold percentile.}
\label{fig:sim_improvements}
\end{figure}
In Fig.~\ref{fig:sim_improvements} we examine how our results might vary if we adopted a similarity-based scoring procedure, by re-evaluating the \texttt{GRU + Attn} model outputs (row 5 in Table \ref{tab:content_exps}) with this evaluation metric.
When the similarity percentile cutoff equals 100, the result is identical to the standard F-1 score.
Even decreasing the cutoff to the 90\textsuperscript{th} percentile shows striking improvements for high-cardinality attributes (180\% for \texttt{mood} and 250\% for \texttt{plot}).
Leveraging a similarity-based scoring procedure for complex tag taxonomies may yield results that more accurately reflect human perception of the model's performance \citep{Maynard2006}.

\subsection{Qualitative Scene-level Analysis}
\label{sec:qual_analysis}
\begin{figure*}[t!]
\centering
    \includegraphics[width=0.75\paperwidth,keepaspectratio]{trajectories.png}
\caption{Descriptor Trajectories for \emph{Pearl Harbor}, \emph{Pretty Woman}, and \emph{Pulp Fiction}. The $y$-axis is a smoothed and rescaled descriptor weight, i.e. $\mathbf{o}_t$ in Eq.\ref{eq:predictor}. Events: (A) Attack on Pearl Harbor begins (B) Rising tension at the equestrian club and (C) Confrontation at the pawn shop. Word clusters corresponding to each descriptor are in Table \ref{tab:clusters}.}
\label{fig:descriptor_trajectories}
\end{figure*}
To extract narrative trajectories with the scene descriptor model, we compared the three model variants in \S\ref{sec:model_architecture} for the choice of scene encoder and found that while attention aids the creation of interpretable descriptors (in-line with previous work), sequential and non-sequential models produce similarly interpretable clusters -- thus, we use the \texttt{BoE+Attn} model.
Similar to \citet{Iyyer2016}, we limit the input vocabulary for both \texttt{BoW + Attn} encoders to words occurring in at least 50 movies (7.3\% of the training set), outside the 500 most frequent words.

The number of descriptors $k$ is set to 25 to allow for a wide range of topics while keeping manual examination feasible.
Descriptors are initialized either randomly \citep{Glorot2010} or with the centroids of a $k$-means clustering of the input word embeddings.
For the predictor, $f$ is a two-layer FFNN with ReLU activations and a softmax final layer that transforms $\mathbf{v}_t$ (from the scene encoder) into a 100-dimensional intermediate state and then into $\mathbf{o}_t$.
Further modeling choices are evaluated using the semantic coherence metric \citep{Mimno2011}, which assesses the quality of word clusters induced by topic modeling algorithms.
These choices include: the presence of recurrence in the predictor (i.e., toggling between Eqns. \ref{eq:predictor} and \ref{eq:recurrent_predictor}, with $\alpha=0.5$) and the value of hyperparameter $\lambda$.
While the $k$-means initialized descriptors score slightly higher on semantic coherence, they are qualitatively quite similar to the initial centroids and do not reflect the corpus as well as the randomly initialized version.
We also find that incorporating recurrence and $\lambda=10$ (tuned using simple grid search) result in the highest coherence.

The outputs of the scene descriptor model are shown in Table \ref{tab:clusters} and Figure \ref{fig:descriptor_trajectories}.
Table \ref{tab:clusters} presents five example descriptors, each identified by representative words closest to them in the word embedding space, with their topic names manually annotated.
Figure \ref{fig:descriptor_trajectories} presents the corresponding narrative trajectories of a subset of these descriptors over the course of three sample screenplays: Pretty Woman, Pulp Fiction, and Pearl Harbor, using a \emph{streamgraph} \citep{Byron2008}.
The descriptor weight $\mathbf{o}_t$ (Eq.\ref{eq:predictor}) as a function of scene order is rescaled and smoothed, with the width of a region at a given scene indicating the weight value.
A critical event for each screenplay is indicated by a letter on each trajectory.
A qualitative analysis of such events indicates general alignment between scripts and their topic trajectories, and the potential applicability of this method to identifying significant moments in long-form documents.

\begin{table}[h!]
\small
\vspace{-0.2cm}
\begin{center}
\begin{tabular}{p{40pt}|l}
\textbf{Topic} & \textbf{Words} \\
\hline
Violence & fires blazes explosions grenade blasts \\
Residential & loft terrace courtyard foyer apartments \\
Military & leadership army victorious commanding elected \\
Vehicles & suv automobile wagon sedan cars \\
Geography & sand slope winds sloping cliffs
\end{tabular}
\end{center}
\caption{\footnotesize Examples of retrieved descriptors. Trajectories for ``Violence", ``Military", and ``Residential" are shown in Fig. \ref{fig:descriptor_trajectories}.}
\label{tab:clusters}
\vspace{-0.2cm}
\end{table}

\section{Related Work}
\label{sec:related}
Computational narrative analysis of large texts has been explored in a number of contexts \citep{Mani2012} and for a number of years \citep{Lehnert1981}.
More recent work has analyzed narrative from a plot \citep{Chambers2008,Goyal2010} and character \citep{Elsner2012,Bamman2014} perspective.
While movie narratives have received attention \citep{Bamman2013,Chaturvedi2018,Kar2018}, the computational analysis of entire screenplays has not been as common.

Notably, \citet{Gorinski2015} introduced a summarization method that takes into account an entire script at a time, extracting graph-based features that summarize the key scene sequences.
\citet{Gorinski2018} then build on top of this work, crafting additional features for use in a specially-designed multi-label encoder.
Our work suggests an orthogonal approach -- our automatically learned scene representations offer an alternative to their feature-engineered inputs.

\citet{Gorinski2018} emphasize the difficulty of their tag prediction task, which we find in our tasks as well.
One possibility we consider is that at least some of this difficulty owes not to the length or richness of the text per se, but rather to the complexity of the tag taxonomy.
The pattern of results we obtain from a similarity-based scoring measure offers a significantly brighter picture of model performance, and suggests more broadly that the standard multilabel F1 measure may not be appropriate for complex, human-crafted tag sets \citep{Maynard2006}.

Nevertheless, dealing with long-form text remains a significant challenge.
One possible solution is to infer richer representations of latent structure by using a structured attention mechanism \citep{Liu2018}, which might highlight key dependencies between scenes in a script.
Another method could be to define auxiliary tasks as in \citet{Jiang2018} to encourage better selection and memorization.
Lastly, sparse versions of the softmax function \citep{Martins2016} can be used to enforce the notion that salient information for downstream tasks is sparsely distributed across the screenplay.

\section{Conclusion}
In this work, we propose and evaluate various neural network architectures for learning fixed-dimensional representations of full-length film scripts.
We hypothesize that designing the network to mimic the documents' internal structure will boost performance. Experiments conducted on two tag prediction tasks provide evidence in favour of this hypothesis, confirming the benefits of (1) using hierarchical attention-based models and (2) incorporating distinctions between different kinds of scene components directly into the model.
Additionally, as a means of exploring the information contained within scene-level embeddings, we presented an unsupervised technique for bootstrapping ``scene descriptors" and visualizing their trajectories through the screenplay.

For future work, we plan to investigate richer ways of incorporating character identities into the model.
For example, character embeddings could be used to analyze character archetypes across different movies.
A persona-based characterization of the screenplay would provide a complementary view to the plot-based analysis elucidated here.

Finally, as noted at the outset, our structure-aware methods are fundamentally generalizable, and can be adapted to natural language understanding across virtually any domain in which structure can be extracted, including books, technical reports, and online chat logs, among others.


\section{Introduction}\label{sec.introduction}
In a world in which technology has been incorporated, both in business and homes, communications have become essential. Due to the centralization of information and storage of data in the cloud, a failure in communications (especially in the business environment) can cause chaos. If this happens in a population nucleus instead of an enterprise, the consequences can be much more serious, especially if it is due to a natural disaster or some kind of catastrophe.

When there is a communications outage situation, it is about finding a solution, establishing a temporary communications point that allows, at least, to have a connection point that allows basic communications to maintain control of the situation.

Unlike centralized communications, decentralized or distributed communications enable direct communication between devices in a network. This means that in this type of communications it is not necessary to have a central device so that the different devices in the network can communicate. Between these two topologies, there is also an intermediate case called hybrid (See Fig.~\ref{networktopologies}).

\begin{figure}[htbp]
\centering
\includegraphics[width=0.45\textwidth]{nettypes.png}
\caption{Network topologies.}
\label{networktopologies}
\end{figure}

In order to establish a communications point in a place where communications have broken down or a temporary communication point is desired, this paper proposes a MANET (Mobile Ad Hoc Network) based on the use of robots that could adopt the acronym R-MANET (Robotic Mobile Ad Hoc Network) or directly RANET (Robotic Ad Hoc Network). The robots will be in charge of forming a multi-hop \cite{ref8} network to finally provide a communications point to the place where the network final nodes (robots) are established.

Robotics has increasingly gone into homes, to the point that we have kitchen robots \cite{ref20}, or robots that clean the floor \cite{ref19} for us. The latter, vacuum cleaners have several advantages such as the possibility of returning automatically to the battery charging station when necessary, so they are being used for other tasks that are not related to cleaning. The proposal therefore uses vacuum robots as network nodes.

In this work, the security of the proposed system is an essential component. We work in the form of authentication of the different network nodes, verifying that each of them are authorized by the network. In addition, a way of encrypting the data is proposed, so that communications are secure and the information will be protected from the sender to the receiver. An IDentity-Based Signcryption (IDBS) \cite{refIDBS} is used for communication confidentiality, authenticity and integrity, both among peers, and between the central station and robots.

The following section discusses a series of works close to the proposal made. Section 3 explains the proposed system in more detail and section 4 also details the components of each robot-based network node. Section 5 shows the security mechanisms used in the proposed system. Finally, a conclusion close the paper.

\section{Related works}\label{sec.relatedworks}
One of the fields in which decentralised communications can be very important is in IoT \cite{ref1} (Internet of Things). More and more devices are connected, and it may be really interesting that between them they form a Wireless Sensor Network (WSN). Many times, this type of network can be the solution for sending data to the cloud when the device does not have a direct Internet connection, but jumping between devices is able to send the information to one with an Internet connection available. In \cite{ref11}, different Multi-Hop routing protocols for Ad Hoc wireless networks are studied and compared. In this type of network, it is important to measure transmission rates between nodes, so that you can choose the optimal way to send information more quickly and efficiently \cite{ref12}.

In IoT, different works are based on the use of Raspberry Pi for data collection through sensors that form WSAN (Wireless Sensor and Actuator Network), which form a MANET between the different devices for data transmission between them \cite{ref9}. Another device used in these sensor networks is the Arduino microcontroller, as in \cite{ref10}, which form a network of sensors for temperature monitoring and to help air conditioning systems operate more efficiently.

The increase in computing capacity of smartphones has also made them useful for decentralized networking. Bluetooth is one of the technologies chosen to form MANET networks between mobile devices \cite{ref13}. These devices are also used to create VANETs that allow the exchange of information between vehicles on the road \cite{ref14}, so that they can share some useful information such as traffic status. The ability to obtain data through built-in sensors means that smartphones can be mounted on a device to move it to one location and obtain data \cite{ref15}, sometimes forming a MANET to deploy several devices at once.

MANET networks are also mounted on drones, such as in \cite{ref2}, where these networks are used to increase the coverage range of the remote control.

The iRobot Roomba robots apart from the tasks for which they have been designed \cite{ref5}, are able to perform other actions thanks to the Open Interface that it has, through which it is possible to send commands. This, in addition to the low cost of these robots, has caused them to be used for different jobs \cite{ref3}. In \cite{ref4}, the authors have worked on the control of an iRobot robot using an external keyboard and voice commands. In \cite{ref6}, a camera is placed on a Roomba robot to compare the captured video with one previously recorded to detect if there are abandoned objects in the examined area. Moreover, by applying fuzzy logic to these robots \cite{ref7} it is possible to develop navigation systems that allow them to obtain more optimal routes while are avoiding obstacles in their path.

In a decentralised network, it is very important to take into account its security. Two of the aspects to be studied are the form of authentication in the network and the protection of the data that is sent between the different nodes until reaching the final destination. Some authors propose models for authentication and auto-configuration of nodes in MANET networks \cite{ref16} and even on preventing impersonation attacks using double authentication factor \cite{ref17}. Apart from this, \cite{ref18} studies different cryptographic protocols for use in MANETs at the level of energy consumption, which is important in mobile devices, concluding that the AES standard is the one that produces the best performance among the different algorithms analyzed.

\section{Proposal description}\label{sec.proposaldescription}
The system proposed in this paper is a MANET in which the different network nodes are robots. The aim is to place the different nodes in the necessary positions to form a network in which a communications point is established at the end point. This communication point will provide the possibility of having a voice and/or data connection in an area that for some reason is out of communication, and where communications with other places are needed. The use of robots as network nodes allows each node to be moved remotely to the desired location, which can be important if it is a dangerous area for people to transport equipment.

To start with the deployment of the robots that will form the network, first you must study the area and calculate the number of nodes needed to extend the network. This calculation is made considering the maximum range of wireless technology used for the connection between the nodes. It should be noted that in general, the theoretical maximum ranges in practice can decrease considerably. The technology chosen to deploy the network is Wi-Fi \cite{ref21}, which has a maximum range of 100 meters. If, for example, we wanted to establish a communications point 500 meters from the starting area, the theory tells us that we would have to form a network with 5 nodes to reach the desired area. To this we must add the base station located at the starting point, from which the signal is transmitted and the network is controlled. The diagram in Fig.~\ref{network} shows the general idea of the proposal.

\begin{figure}[htbp]
\centering
\includegraphics[width=0.489\textwidth]{network2.png}
\caption{Network scheme.}
\label{network}
\end{figure}

The system proposed to deploy a temporary communication point through the use of robots is based on different functionalities: remote control of robots, streaming, object tracking and wireless network deployment.

First of all, there is the remote control of robots. This functionality allows each node of the network to be moved remotely to the point where it has been previously decided. From the base station it is possible to select a robot within the network and send it real-time movement commands.

Secondly, we have audio and video streaming \cite{ref22}. To be able to move the robots remotely, it is necessary to know where they are at any given moment, so this second functionality is essential. Thanks to streaming, it is possible to visualize the environment in which the robot is located, at the same time that it is remotely controlled from the base station. In addition, audio is included in the streaming in case it would be useful to listen to the sound of the environment in which it is moving. To carry out this functionality, the base station must have a streaming server to which each robot will send the audio and video signal. The RTSP protocol \cite{ref23} is used to send this signal from the robots to the streaming server, and the RTMP protocol \cite{ref24} is used for receiving the video from the server to the base station equipment. In both cases, port 1935 is used (See Fig.~\ref{streaming}).

\begin{figure}[htbp]
\centering
\includegraphics[width=0.489\textwidth]{streaming3.png}
\caption{Streaming scheme.}
\label{streaming}
\end{figure}

To perform these two functions, a web application is incorporated in the base station. It shows different blocks, and each one of the blocks refers to a robot, showing in them the video received through streaming together with buttons that allow sending movement orders to each robot.

Third is object tracking \cite{ref25}, which is used for the most interesting part of the proposal. Directing each robot remotely to the desired location can be a tedious task (especially if the number of nodes is too large), so it is proposed that by controlling only one of the robots the rest will be able to follow it autonomously. For this, a master node will be selected and the rest will be slaves of it. Each robot has a QR code on the back that identifies it within the network. Each slave robot has to do image recognition, looking for any QR code in the images captured by your camera. This is when the robot has to check if the detected QR code corresponds with the robot you have programmed to follow. The flowchart of Fig.~\ref{trackingflowchart} shows this process.

\begin{figure}[htbp]
\centering
\includegraphics[width=0.25\textwidth]{trackingflowchart.png}
\caption{Flowchart of robot tracking.}
\label{trackingflowchart}
\end{figure}

Once a slave robot has detected the QR code of the robot to be followed, it performs calculations to establish the adequate movement. To do this, a proximity sensor is used, so that if the robot is more than a certain distance away, it has to start following the predecessor robot. In addition, depending on the area of the image in which the QR of the front node is detected, it will move in a certain direction (See Fig.~\ref{qrdetection}).

\begin{figure}[htbp]
\centering
\includegraphics[width=0.48\textwidth]{tracking2.jpg}
\caption{QR detection.}
\label{qrdetection}
\end{figure}

The latest functionality is responsible for deploying a wireless network at each node of the network. Each robot receives the Wi-Fi signal from its predecessor, so that it can have a connection to the base station by jumping between the different nodes in the network. In turn, they need to deploy a new Wi-Fi network so that the next node can connect to it to maintain a connection chain between the base station and the end node.

\section{Node description}\label{sec.nodedescription}
So far, the proposed system for deploying a RANET has been described, but the technologies and elements available to each network node have not been defined. It has also not been specified what type of robot is used.

Each node is built around an iRobot Roomba \cite{ref31} vacuum robot, which is connected to a Raspberry Pi, these two forming the core of the node. The Raspberry Pi is connected to the robot to send commands to it and is also responsible for establishing communications with the base station and the other nodes of the network.

As can be seen in the connection diagram of the different elements (See Fig.~\ref{node}), the Raspberry Pi is the central element of the node (all elements are connected to it thanks to the USB ports that it incorporates, GPIO pins or ports for specific use).

\begin{figure}[htbp]
\centering
\includegraphics[width=0.489\textwidth]{node.png}
\caption{Node wiring diagram.}
\label{node}
\end{figure}

First of all there is the camera, which is connected through a specific port that incorporates the Raspberry Pi. Second are the USB ports, which are used to connect a second Wi-Fi adapter and a microphone for audio reception. Thirdly, an ultrasonic sensor is connected to the GPIO pins for detecting obstacles (adding a resistance that adjusts the tension provided on the Raspberry Pi) and the Roomba robot. To connect the robot, a resistive voltage divider \cite{ref32} is incorporated in the Roomba transmission pin to reduce the 5V supplied by it to a maximum of 3.3V, which allows the Raspberry Pi reception port.

$$ V_{out} = \frac{R_{2}}{R_{1} + R_{2}} \cdot V_{in} $$

And finally there is the connection of the Raspberry Pi's power supply. Taking advantage of the fact that the Roomba is able to provide power to external devices, the battery is used to avoid having to incorporate an external one, using a voltage regulator that converts the 14.4V that provides the Roomba battery to the 5V that Raspberry Pi needs.

In addition to the Wi-Fi interface that Raspberry Pi incorporates, a second interface has been added through the USB port to extend the network that gets the first interface, so that an interface is used in the usual reception mode, and the second is configured in Ad Hoc mode. For simpler configuration of network interfaces, as well as to allow external devices to connect to wireless networks created by different network nodes, a single class B network \cite{ref33} will be configured, which allows the connection of 65534 devices (discounting the base station and broadcast address), among which may be network nodes, or end devices. It should be noted that each network node will use 2 IP addresses, as it has two wireless cards; instead, each end device will use a single IP address. IP addressing of devices connected to the network is carried out automatically thanks to the incorporation of a DHCP server in the base station. To do this, a range of addresses is reserved for the network nodes, and all other addresses are assigned automatically.

\section{Security}\label{sec.security}
The security of communications is a crucial point of the system.
An ID-Based Signcryption scheme (IBSC) is used in order to achieve secure communications.
This kind of cryptosystem is a combination of ID-Based Encryption (IBE) and ID-Based Signature (IBS), where all the shared messages are encrypted and signed.
This proposed scheme offers the advantage of simplifying management of keys by not having to define a public key infrastructure.
A part of this, this scheme has a low computational complexity and it is efficient in terms of memory.
In this RANET system, the identification of nodes is a crucial point.
Each robot has a QR code on the back that identifies it with a unique ID, this is the public identification used for the IBSC.

First of all, some mathematical tools used is described.
Let consider $(G, +)$ and $(V, \cdot)$ be two cyclic groups of the same prime order $q$.
$P$ is a generator of $G$ and there is a bilinear map paring $\hat{e} : G \times G \rightarrow V$
satisfying the following conditions:

\begin{itemize}
	\item Bilinear: $ \forall P, Q \in G$ and $\forall a, b \in \mathbb{Z}$, $\hat{e}(aP, bQ)
= \hat{e}(P, Q)^{ab} $
	\item Non-degenerate: $ \exists P_1, P_2 \in G $ that $\hat{e}(P_1,P_2) \neq 1$. This means if $P$ is generator of $G$, then $\hat{e}(P,P)$ is a generator of $Q$.
	\item Computability: there exists an algorithm to compute $\hat{e}(P,Q), \forall P,Q \in G$
\end{itemize}

\par Note, some hash functions denoted as follows are also needed: $H_1: \{0, 1\}^* \rightarrow G^*, H_2 : \{0, 1\}^* \rightarrow \mathbb{Z}^*_q, H_3 : \mathbb{Z}^*_q \rightarrow \{0, 1\}^n$,
where the size of the message is defined by $n$.
Apart of this, $a \xleftarrow{r} N$ denotes a selection of an element $a$ randomly from a set $N$,
$a \leftarrow b$ stands the assignation of the value $a$ to $b$ and $||$ is used for concatenation.

The steps used in this signcryption scheme are the following:

	\begin{itemize}
		\renewcommand{\labelitemi}{$\bullet$}

		\item \textbf{SETUP:} This step is execute in the base station to the establishment of the basic parameters and to the generation of the base station public key ($pk_{bs}$) and the base station secret key ($sk_{bs}$). To achieve this, a prime value $q$ is generated based on some private data $k \in \mathbb{Z}$ and the system select two groups $G$ and $V$ of order $q$ and a bilinear pairing map $\hat{e}: G \times G \rightarrow V$. $P \in G$ is selected randomly and the hash functions $H_1$, $H_2$ and $H_3$ are also chosen.

$$ pk_{bs} \stackrel{r}{\leftarrow}  \mathbb{Z}^*_q $$
$$ sk_{bs} \leftarrow pk_{bs} \cdot P $$

		\item \textbf{EXTRACT ($ID_r$):} In this step, the keys for each robot is generated based on their ID.
		The robot $r$ with the identity $ID_r$ sends its information to the base station.
		The public key $Q_{ID_r} \in G$ and the secret key $S_{ID_r} \in G$ are calculated taking into account the $sk_{bs}$.
		This key exchange of data is performed in a secure way

$$ Q_{ID_r} \leftarrow H_1(ID_r) $$
$$ S_{ID_r} \leftarrow  sk_{bs} \cdot Q_{ID_r} $$

		\item \textbf{SIGNCRYPTION ($S_{ID_{ra}}$, $ID_{rb}$, $m$):} If a robot $A$ with the identity $ID_{ra}$ shares a message $m \in\{0,1\}^n$ to the robot $B$ with the identity
		$ID_{rb}$, the information will be encrypted and signed. The robot receiver's public key is generated taking into account the $ID_{rb}$ and then the message is signed with $S_{ID_{ra}}$ and encrypted with $Q_{ID_{rb}}$ giving as result $\sigma$ (a t-uple of three components: c, T, U).

$$ Q_{ID_{rb}} \leftarrow H_1(ID_{rb}) $$
$$ x \stackrel{r}{\leftarrow}\mathbb{Z}^*_q$$
$$ T \leftarrow x \cdot P$$
$$ r \leftarrow H_2(T || m)$$
$$ W \leftarrow x \cdot pk_{bs}$$
$$ U \leftarrow r \cdot S_{ID_{ra}} + W $$
$$ y \leftarrow \hat{e}(W, Q_{ID_{rb}}) $$
$$ k \leftarrow H_3(y)$$
$$ c \leftarrow k \oplus m$$
$$ \sigma \leftarrow (c, T, U)$$

	\item \textbf{UNSIGNCRYPTION ($ID_{ra}$, $S_{ID_{rb}}$, $\sigma$):} The robot $B$ receive $\sigma$ and parse the information.
	If everything is right, the message $m \in \{0,1\}^n$ is returned. Otherwise, if there are some problems in
the signature or in the encryption of $m$, $\bot$ is returned. The sender's public key is
generated taking into account $ID_{ra}$ and then the message is unencrypted with $S_{ID_{rb}}$.

$$ Q_{ID_{ra}} \leftarrow H_1(ID_{ra}) $$
$$ split \quad \sigma \quad as \quad (c, T, U) $$
$$ y \leftarrow \hat{e}(S_{ID_{rb}}, T)$$
$$ k \leftarrow y $$
$$ m \leftarrow k \oplus c $$
$$ r \leftarrow H_2(T || m) $$

Verification:
$$\hat{e}(U, P) == \hat{e}(Q_{ID_{ra}}, pk_{bs} )^r \cdot \hat{e}(T, pk_{bs})$$
Note: if the verification is successful  $m$ is returned, otherwise $\bot$ is returned.

\end{itemize}

\section{Conclusion}\label{sec.conclusion}
MANET networks allow the connection between different devices and exchange information in a decentralized way. The behavior of such networks is similar to that of a P2P network. The main characteristic of this network is that the different nodes that form it are in motion. In a MANET network with robots, the ability to move nodes remotely is added. In this way it is not necessary to go to the different points where the nodes will be located, but it is possible to move them remotely thanks to streaming video visualization. In addition, the proposal incorporates object tracking, which allows that when moving one of the robots the rest moves behind the first one in an autonomous way.

Using Raspberry Pi as the primary device for each network node gives the system many possibilities. Having a device that runs a Linux operating system gives the possibility to add different services that run for some purpose and the development of applications that may be useful for system users. The USB ports and GPIO pins for device connection provide the possibility of adding different types of sensors for data acquisition or even actuators that can interact with the environment. The low battery consumption of these devices gives the possibility to use a small battery as a power source for these devices, as well as allowing a long use of them before draining the electricity provided by the battery.

In the proposed system, Wi-Fi is used as wireless technology in order to take advantage of the interface that incorporates Raspberry Pi, but it is possible to use any other type of wireless technology, allowing a greater range of coverage, which has an interface that can be connected to Raspberry Pi.

The incorporation of security mechanisms provides added value to the system, so that it can ensure that client devices connected to the generated network are secure. Using Identity-Based Cryptography we are able to provide the information encryption and authentication system by signing, with a low computational complexity.

Apart from the functionality for which this system has been designed, it can be used to perform video surveillance tasks using the camera and microphone incorporated in each of the network nodes, and can be moved thanks to robots to view images from different areas. This can be quite useful in hard-to-reach areas, or where people's physical integrity may be at risk.

To improve object tracking, in this case QR codes, in the future the design can be improved by including a small screen in the back of each robot. In this way, the permanent QR code is replaced by a screen that would allow the code to be changed from time to time. This change brings extra security to the system, since every few minutes the code used would become obsolete, thus preventing anyone from being able to move the robots to another location using a QR code that is too old.

\section*{Acknowledgments}
Research supported by the Spanish Ministry of Economy and Competitiveness, TESIS2015010102, the European FEDER Fund, and the CajaCanarias Foundation, under Projects TEC2014-54110-R, RTC-2014-1648-8, MTM2015-69138-REDT and DIG02-INSITU.

\section{Introduction}\label{sec.introduction}
In a world in which technology has been incorporated, both in business and homes, communications have become essential. Due to the centralization of information and storage of data in the cloud, a failure in communications (especially in the business environment) can cause chaos. If this happens in a population nucleus instead of an enterprise, the consequences can be much more serious, especially if it is due to a natural disaster or some kind of catastrophe.

When there is a communications outage situation, it is about finding a solution, establishing a temporary communications point that allows, at least, to have a connection point that allows basic communications to maintain control of the situation.

Unlike centralized communications, decentralized or distributed communications enable direct communication between devices in a network. This means that in this type of communications it is not necessary to have a central device so that the different devices in the network can communicate. Between these two topologies, there is also an intermediate case called hybrid (See Fig.~\ref{networktopologies}).

\begin{figure}[htbp]
\centering
\includegraphics[width=0.45\textwidth]{nettypes.png}
\caption{Network topologies.}
\label{networktopologies}
\end{figure}

In order to establish a communications point in a place where communications have broken down or a temporary communication point is desired, this paper proposes a MANET (Mobile Ad Hoc Network) based on the use of robots that could adopt the acronym R-MANET (Robotic Mobile Ad Hoc Network) or directly RANET (Robotic Ad Hoc Network). The robots will be in charge of forming a multi-hop \cite{ref8} network to finally provide a communications point to the place where the network final nodes (robots) are established.

Robotics has increasingly gone into homes, to the point that we have kitchen robots \cite{ref20}, or robots that clean the floor \cite{ref19} for us. The latter, vacuum cleaners have several advantages such as the possibility of returning automatically to the battery charging station when necessary, so they are being used for other tasks that are not related to cleaning. The proposal therefore uses vacuum robots as network nodes.

In this work, the security of the proposed system is an essential component. We work in the form of authentication of the different network nodes, verifying that each of them are authorized by the network. In addition, a way of encrypting the data is proposed, so that communications are secure and the information will be protected from the sender to the receiver. An IDentity-Based Signcryption (IDBS) \cite{refIDBS} is used for communication confidentiality, authenticity and integrity, both among peers, and between the central station and robots.

The following section discusses a series of works close to the proposal made. Section 3 explains the proposed system in more detail and section 4 also details the components of each robot-based network node. Section 5 shows the security mechanisms used in the proposed system. Finally, a conclusion close the paper.

\section{Related works}\label{sec.relatedworks}
One of the fields in which decentralised communications can be very important is in IoT \cite{ref1} (Internet of Things). More and more devices are connected, and it may be really interesting that between them they form a Wireless Sensor Network (WSN). Many times, this type of network can be the solution for sending data to the cloud when the device does not have a direct Internet connection, but jumping between devices is able to send the information to one with an Internet connection available. In \cite{ref11}, different Multi-Hop routing protocols for Ad Hoc wireless networks are studied and compared. In this type of network, it is important to measure transmission rates between nodes, so that you can choose the optimal way to send information more quickly and efficiently \cite{ref12}.

In IoT, different works are based on the use of Raspberry Pi for data collection through sensors that form WSAN (Wireless Sensor and Actuator Network), which form a MANET between the different devices for data transmission between them \cite{ref9}. Another device used in these sensor networks is the Arduino microcontroller, as in \cite{ref10}, which form a network of sensors for temperature monitoring and to help air conditioning systems operate more efficiently.

The increase in computing capacity of smartphones has also made them useful for decentralized networking. Bluetooth is one of the technologies chosen to form MANET networks between mobile devices \cite{ref13}. These devices are also used to create VANETs that allow the exchange of information between vehicles on the road \cite{ref14}, so that they can share some useful information such as traffic status. The ability to obtain data through built-in sensors means that smartphones can be mounted on a device to move it to one location and obtain data \cite{ref15}, sometimes forming a MANET to deploy several devices at once.

MANET networks are also mounted on drones, such as in \cite{ref2}, where these networks are used to increase the coverage range of the remote control.

The iRobot Roomba robots apart from the tasks for which they have been designed \cite{ref5}, are able to perform other actions thanks to the Open Interface that it has, through which it is possible to send commands. This, in addition to the low cost of these robots, has caused them to be used for different jobs \cite{ref3}. In \cite{ref4}, the authors have worked on the control of an iRobot robot using an external keyboard and voice commands. In \cite{ref6}, a camera is placed on a Roomba robot to compare the captured video with one previously recorded to detect if there are abandoned objects in the examined area. Moreover, by applying fuzzy logic to these robots \cite{ref7} it is possible to develop navigation systems that allow them to obtain more optimal routes while are avoiding obstacles in their path.

In a decentralised network, it is very important to take into account its security. Two of the aspects to be studied are the form of authentication in the network and the protection of the data that is sent between the different nodes until reaching the final destination. Some authors propose models for authentication and auto-configuration of nodes in MANET networks \cite{ref16} and even on preventing impersonation attacks using double authentication factor \cite{ref17}. Apart from this, \cite{ref18} studies different cryptographic protocols for use in MANETs at the level of energy consumption, which is important in mobile devices, concluding that the AES standard is the one that produces the best performance among the different algorithms analyzed.

\section{Proposal description}\label{sec.proposaldescription}
The system proposed in this paper is a MANET in which the different network nodes are robots. The aim is to place the different nodes in the necessary positions to form a network in which a communications point is established at the end point. This communication point will provide the possibility of having a voice and/or data connection in an area that for some reason is out of communication, and where communications with other places are needed. The use of robots as network nodes allows each node to be moved remotely to the desired location, which can be important if it is a dangerous area for people to transport equipment.

To start with the deployment of the robots that will form the network, first you must study the area and calculate the number of nodes needed to extend the network. This calculation is made considering the maximum range of wireless technology used for the connection between the nodes. It should be noted that in general, the theoretical maximum ranges in practice can decrease considerably. The technology chosen to deploy the network is Wi-Fi \cite{ref21}, which has a maximum range of 100 meters. If, for example, we wanted to establish a communications point 500 meters from the starting area, the theory tells us that we would have to form a network with 5 nodes to reach the desired area. To this we must add the base station located at the starting point, from which the signal is transmitted and the network is controlled. The diagram in Fig.~\ref{network} shows the general idea of the proposal.

\begin{figure}[htbp]
\centering
\includegraphics[width=0.489\textwidth]{network2.png}
\caption{Network scheme.}
\label{network}
\end{figure}

The system proposed to deploy a temporary communication point through the use of robots is based on different functionalities: remote control of robots, streaming, object tracking and wireless network deployment.

First of all, there is the remote control of robots. This functionality allows each node of the network to be moved remotely to the point where it has been previously decided. From the base station it is possible to select a robot within the network and send it real-time movement commands.

Secondly, we have audio and video streaming \cite{ref22}. To be able to move the robots remotely, it is necessary to know where they are at any given moment, so this second functionality is essential. Thanks to streaming, it is possible to visualize the environment in which the robot is located, at the same time that it is remotely controlled from the base station. In addition, audio is included in the streaming in case it would be useful to listen to the sound of the environment in which it is moving. To carry out this functionality, the base station must have a streaming server to which each robot will send the audio and video signal. The RTSP protocol \cite{ref23} is used to send this signal from the robots to the streaming server, and the RTMP protocol \cite{ref24} is used for receiving the video from the server to the base station equipment. In both cases, port 1935 is used (See Fig.~\ref{streaming}).

\begin{figure}[htbp]
\centering
\includegraphics[width=0.489\textwidth]{streaming3.png}
\caption{Streaming scheme.}
\label{streaming}
\end{figure}

To perform these two functions, a web application is incorporated in the base station. It shows different blocks, and each one of the blocks refers to a robot, showing in them the video received through streaming together with buttons that allow sending movement orders to each robot.

Third is object tracking \cite{ref25}, which is used for the most interesting part of the proposal. Directing each robot remotely to the desired location can be a tedious task (especially if the number of nodes is too large), so it is proposed that by controlling only one of the robots the rest will be able to follow it autonomously. For this, a master node will be selected and the rest will be slaves of it. Each robot has a QR code on the back that identifies it within the network. Each slave robot has to do image recognition, looking for any QR code in the images captured by your camera. This is when the robot has to check if the detected QR code corresponds with the robot you have programmed to follow. The flowchart of Fig.~\ref{trackingflowchart} shows this process.

\begin{figure}[htbp]
\centering
\includegraphics[width=0.25\textwidth]{trackingflowchart.png}
\caption{Flowchart of robot tracking.}
\label{trackingflowchart}
\end{figure}

Once a slave robot has detected the QR code of the robot to be followed, it performs calculations to establish the adequate movement. To do this, a proximity sensor is used, so that if the robot is more than a certain distance away, it has to start following the predecessor robot. In addition, depending on the area of the image in which the QR of the front node is detected, it will move in a certain direction (See Fig.~\ref{qrdetection}).

\begin{figure}[htbp]
\centering
\includegraphics[width=0.48\textwidth]{tracking2.jpg}
\caption{QR detection.}
\label{qrdetection}
\end{figure}

The latest functionality is responsible for deploying a wireless network at each node of the network. Each robot receives the Wi-Fi signal from its predecessor, so that it can have a connection to the base station by jumping between the different nodes in the network. In turn, they need to deploy a new Wi-Fi network so that the next node can connect to it to maintain a connection chain between the base station and the end node.

\section{Node description}\label{sec.nodedescription}
So far, the proposed system for deploying a RANET has been described, but the technologies and elements available to each network node have not been defined. It has also not been specified what type of robot is used.

Each node is built around an iRobot Roomba \cite{ref31} vacuum robot, which is connected to a Raspberry Pi, these two forming the core of the node. The Raspberry Pi is connected to the robot to send commands to it and is also responsible for establishing communications with the base station and the other nodes of the network.

As can be seen in the connection diagram of the different elements (See Fig.~\ref{node}), the Raspberry Pi is the central element of the node (all elements are connected to it thanks to the USB ports that it incorporates, GPIO pins or ports for specific use).

\begin{figure}[htbp]
\centering
\includegraphics[width=0.489\textwidth]{node.png}
\caption{Node wiring diagram.}
\label{node}
\end{figure}

First of all there is the camera, which is connected through a specific port that incorporates the Raspberry Pi. Second are the USB ports, which are used to connect a second Wi-Fi adapter and a microphone for audio reception. Thirdly, an ultrasonic sensor is connected to the GPIO pins for detecting obstacles (adding a resistance that adjusts the tension provided on the Raspberry Pi) and the Roomba robot. To connect the robot, a resistive voltage divider \cite{ref32} is incorporated in the Roomba transmission pin to reduce the 5V supplied by it to a maximum of 3.3V, which allows the Raspberry Pi reception port.

$$ V_{out} = \frac{R_{2}}{R_{1} + R_{2}} \cdot V_{in} $$

And finally there is the connection of the Raspberry Pi's power supply. Taking advantage of the fact that the Roomba is able to provide power to external devices, the battery is used to avoid having to incorporate an external one, using a voltage regulator that converts the 14.4V that provides the Roomba battery to the 5V that Raspberry Pi needs.

In addition to the Wi-Fi interface that Raspberry Pi incorporates, a second interface has been added through the USB port to extend the network that gets the first interface, so that an interface is used in the usual reception mode, and the second is configured in Ad Hoc mode. For simpler configuration of network interfaces, as well as to allow external devices to connect to wireless networks created by different network nodes, a single class B network \cite{ref33} will be configured, which allows the connection of 65534 devices (discounting the base station and broadcast address), among which may be network nodes, or end devices. It should be noted that each network node will use 2 IP addresses, as it has two wireless cards; instead, each end device will use a single IP address. IP addressing of devices connected to the network is carried out automatically thanks to the incorporation of a DHCP server in the base station. To do this, a range of addresses is reserved for the network nodes, and all other addresses are assigned automatically.

\section{Security}\label{sec.security}
The security of communications is a crucial point of the system.
An ID-Based Signcryption scheme (IBSC) is used in order to achieve secure communications.
This kind of cryptosystem is a combination of ID-Based Encryption (IBE) and ID-Based Signature (IBS), where all the shared messages are encrypted and signed.
This proposed scheme offers the advantage of simplifying management of keys by not having to define a public key infrastructure.
A part of this, this scheme has a low computational complexity and it is efficient in terms of memory.
In this RANET system, the identification of nodes is a crucial point.
Each robot has a QR code on the back that identifies it with a unique ID, this is the public identification used for the IBSC.

First of all, some mathematical tools used is described.
Let consider $(G, +)$ and $(V, \cdot)$ be two cyclic groups of the same prime order $q$.
$P$ is a generator of $G$ and there is a bilinear map paring $\hat{e} : G \times G \rightarrow V$
satisfying the following conditions:

\begin{itemize}
	\item Bilinear: $ \forall P, Q \in G$ and $\forall a, b \in \mathbb{Z}$, $\hat{e}(aP, bQ)
= \hat{e}(P, Q)^{ab} $
	\item Non-degenerate: $ \exists P_1, P_2 \in G $ that $\hat{e}(P_1,P_2) \neq 1$. This means if $P$ is generator of $G$, then $\hat{e}(P,P)$ is a generator of $Q$.
	\item Computability: there exists an algorithm to compute $\hat{e}(P,Q), \forall P,Q \in G$
\end{itemize}

\par Note, some hash functions denoted as follows are also needed: $H_1: \{0, 1\}^* \rightarrow G^*, H_2 : \{0, 1\}^* \rightarrow \mathbb{Z}^*_q, H_3 : \mathbb{Z}^*_q \rightarrow \{0, 1\}^n$,
where the size of the message is defined by $n$.
Apart of this, $a \xleftarrow{r} N$ denotes a selection of an element $a$ randomly from a set $N$,
$a \leftarrow b$ stands the assignation of the value $a$ to $b$ and $||$ is used for concatenation.

The steps used in this signcryption scheme are the following:

	\begin{itemize}
		\renewcommand{\labelitemi}{$\bullet$}

		\item \textbf{SETUP:} This step is execute in the base station to the establishment of the basic parameters and to the generation of the base station public key ($pk_{bs}$) and the base station secret key ($sk_{bs}$). To achieve this, a prime value $q$ is generated based on some private data $k \in \mathbb{Z}$ and the system select two groups $G$ and $V$ of order $q$ and a bilinear pairing map $\hat{e}: G \times G \rightarrow V$. $P \in G$ is selected randomly and the hash functions $H_1$, $H_2$ and $H_3$ are also chosen.

$$ pk_{bs} \stackrel{r}{\leftarrow}  \mathbb{Z}^*_q $$
$$ sk_{bs} \leftarrow pk_{bs} \cdot P $$

		\item \textbf{EXTRACT ($ID_r$):} In this step, the keys for each robot is generated based on their ID.
		The robot $r$ with the identity $ID_r$ sends its information to the base station.
		The public key $Q_{ID_r} \in G$ and the secret key $S_{ID_r} \in G$ are calculated taking into account the $sk_{bs}$.
		This key exchange of data is performed in a secure way

$$ Q_{ID_r} \leftarrow H_1(ID_r) $$
$$ S_{ID_r} \leftarrow  sk_{bs} \cdot Q_{ID_r} $$

		\item \textbf{SIGNCRYPTION ($S_{ID_{ra}}$, $ID_{rb}$, $m$):} If a robot $A$ with the identity $ID_{ra}$ shares a message $m \in\{0,1\}^n$ to the robot $B$ with the identity
		$ID_{rb}$, the information will be encrypted and signed. The robot receiver's public key is generated taking into account the $ID_{rb}$ and then the message is signed with $S_{ID_{ra}}$ and encrypted with $Q_{ID_{rb}}$ giving as result $\sigma$ (a t-uple of three components: c, T, U).

$$ Q_{ID_{rb}} \leftarrow H_1(ID_{rb}) $$
$$ x \stackrel{r}{\leftarrow}\mathbb{Z}^*_q$$
$$ T \leftarrow x \cdot P$$
$$ r \leftarrow H_2(T || m)$$
$$ W \leftarrow x \cdot pk_{bs}$$
$$ U \leftarrow r \cdot S_{ID_{ra}} + W $$
$$ y \leftarrow \hat{e}(W, Q_{ID_{rb}}) $$
$$ k \leftarrow H_3(y)$$
$$ c \leftarrow k \oplus m$$
$$ \sigma \leftarrow (c, T, U)$$

	\item \textbf{UNSIGNCRYPTION ($ID_{ra}$, $S_{ID_{rb}}$, $\sigma$):} The robot $B$ receive $\sigma$ and parse the information.
	If everything is right, the message $m \in \{0,1\}^n$ is returned. Otherwise, if there are some problems in
the signature or in the encryption of $m$, $\bot$ is returned. The sender's public key is
generated taking into account $ID_{ra}$ and then the message is unencrypted with $S_{ID_{rb}}$.

$$ Q_{ID_{ra}} \leftarrow H_1(ID_{ra}) $$
$$ split \quad \sigma \quad as \quad (c, T, U) $$
$$ y \leftarrow \hat{e}(S_{ID_{rb}}, T)$$
$$ k \leftarrow y $$
$$ m \leftarrow k \oplus c $$
$$ r \leftarrow H_2(T || m) $$

Verification:
$$\hat{e}(U, P) == \hat{e}(Q_{ID_{ra}}, pk_{bs} )^r \cdot \hat{e}(T, pk_{bs})$$
Note: if the verification is successful  $m$ is returned, otherwise $\bot$ is returned.

\end{itemize}

\section{Conclusion}\label{sec.conclusion}
MANET networks allow the connection between different devices and exchange information in a decentralized way. The behavior of such networks is similar to that of a P2P network. The main characteristic of this network is that the different nodes that form it are in motion. In a MANET network with robots, the ability to move nodes remotely is added. In this way it is not necessary to go to the different points where the nodes will be located, but it is possible to move them remotely thanks to streaming video visualization. In addition, the proposal incorporates object tracking, which allows that when moving one of the robots the rest moves behind the first one in an autonomous way.

Using Raspberry Pi as the primary device for each network node gives the system many possibilities. Having a device that runs a Linux operating system gives the possibility to add different services that run for some purpose and the development of applications that may be useful for system users. The USB ports and GPIO pins for device connection provide the possibility of adding different types of sensors for data acquisition or even actuators that can interact with the environment. The low battery consumption of these devices gives the possibility to use a small battery as a power source for these devices, as well as allowing a long use of them before draining the electricity provided by the battery.

In the proposed system, Wi-Fi is used as wireless technology in order to take advantage of the interface that incorporates Raspberry Pi, but it is possible to use any other type of wireless technology, allowing a greater range of coverage, which has an interface that can be connected to Raspberry Pi.

The incorporation of security mechanisms provides added value to the system, so that it can ensure that client devices connected to the generated network are secure. Using Identity-Based Cryptography we are able to provide the information encryption and authentication system by signing, with a low computational complexity.

Apart from the functionality for which this system has been designed, it can be used to perform video surveillance tasks using the camera and microphone incorporated in each of the network nodes, and can be moved thanks to robots to view images from different areas. This can be quite useful in hard-to-reach areas, or where people's physical integrity may be at risk.

To improve object tracking, in this case QR codes, in the future the design can be improved by including a small screen in the back of each robot. In this way, the permanent QR code is replaced by a screen that would allow the code to be changed from time to time. This change brings extra security to the system, since every few minutes the code used would become obsolete, thus preventing anyone from being able to move the robots to another location using a QR code that is too old.

\section*{Acknowledgments}
Research supported by the Spanish Ministry of Economy and Competitiveness, TESIS2015010102, the European FEDER Fund, and the CajaCanarias Foundation, under Projects TEC2014-54110-R, RTC-2014-1648-8, MTM2015-69138-REDT and DIG02-INSITU.


\section{\label{}}

\section{EXTRA-SPECTRAL COMPONENTS}

Most of the prompt emission spectra of gamma-ray bursts (GRBs)
can be described by the well-known Band function \citep{ban93};
the photon number spectrum
$\propto \varepsilon^{\alpha}$
below $\varepsilon_{\rm p}$,
and $\propto \varepsilon^{\beta}$ above it.
The spectral peak energy $\varepsilon_{\rm p}$
are usually seen in the MeV range.
One of main scientific targets for the {\it Fermi} satellite
was to investigate whether the spectral shape is consistent
with the Band function even in the GeV band.
The {\it Fermi} detected GeV photons from
several very bright bursts ($E_{\rm iso}>10^{54}$ erg) such as
GRB 080916C \citep{916C}, GRB 090902B \citep{902B}, and
GRB 090926A \citep{926A}.
In such bursts the onset of the GeV emission is delayed with respect to
the MeV emission.
Some of them also have an extra spectral component above a
few GeV, distinct and additional to the usual Band function.
Interestingly, GRB 090902B and GRB 090510 \citep{abd09b,ack10} show
a further, soft excess feature below $\sim 20$ keV,
which is consistent with a continuation of the GeV power-law component.
While such spectra may be explained by the early onset of the afterglow
\citep{ghi10,kum10}, here we pursue possibility of internal-shock origins.

\section{HADRONIC MODELS}

If the spectral excesses in GeV and keV bands have
the same origin, such a wide photon-energy range may imply
the cascade emission due to hadrons.
If the GRB accelerated ultra-high-energy protons,
synchrotron and inverse Compton (IC) emission from
an electron-positron pair cascade
triggered by photopion interactions of
the protons with low-energy photons \citep{boe98,gup07,asa07}
can reproduce power-law photon spectra
as seen in {\it Fermi}-LAT GRBs.
Through Monte Carlo simulations,
Asano et al. \citep{asa09b} have shown that
a proton luminosity much larger than gamma-ray luminosity is required
to produce the extra spectral component in GRB 090510
as $L_{\rm p}>10^{55}$ erg $\mbox{s}^{-1}$ (see Fig.\ref{f1}).
Namely, the efficiency of photopion production is very low.
In this case, the spectrum of the GeV component
is very hard with photon index $\sim -1.6$,
which requires a inverse Compton (IC) contribution from the secondary pairs.
The prominent IC component leads to
a weaker magnetic field.
This entails a lower maximum energy of protons,
and hence lower photopion production efficiency.
Therefore, the required proton luminosity
is so large in GRB 090510.

\begin{figure*}[t]
\includegraphics[width=70mm]{fA1.eps}
\caption{Simulated spectra with hadronic models for GRB 090510.
The assumed fraction of the magnetic energy density
to the Band component photons is $10^{-3}$,
and the required proton luminosity
is 200 times the luminosity of the Band component.}
\label{f1}
\end{figure*}

\begin{figure*}[t]
\includegraphics[width=70mm]{fA2.eps}
\caption{Simulated spectra with hadronic models for GRB 090902B.
The assumed fraction of the magnetic energy density
to the Band component photons is $1.0$, and
the required proton luminosity
is 3 times the luminosities of the Band component.}
\label{f2}
\end{figure*}

The assumed bulk Lorentz factor in Fig.\ref{f1} is 1500,
and the emission radius is $R=10^{14}$ cm.
If we adopt a smaller value of $\Gamma$,
the pion production efficiency would increases as
$t_{\rm exp}/t_\pi \propto R^{-1} \Gamma^{-2}$.
However, we should note that there is a lower limit to $\Gamma$,
which is required to
make the source optically thin to GeV photons.
Given the photon luminosity and spectral shape,
this minimum Lorentz factor can be estimated as shown
in the online supporting materials
in Abdo et al. (2009) \citep{916C}.
In order to lower $\Gamma$, we have to increase
the emission radius $R$.
The lower limit of the Lorentz factor
$\propto R^{1/(\beta-3)}$ does not decrease drastically
(since $\beta \simeq -3$, $\Gamma_{\rm min} \propto R^{-1/6}$).
The required large luminosity is rather favorable
for the GRB-UHECR scenario, but it imposes stringent requirements
on the energy budget of the central engine.

On the other hand, GRB 090902B is encouraging for the hadronic model
because of its flat spectrum (photon index $\sim -2$)
\citep{asa10}.
The Band component in this burst
is an atypically narrow energy distribution
as shown in Fig. \ref{f2},
which may imply the photospheric emission \citep{ryd10}.
The hadronic cascade emission can well reproduce the
observed flat spectra including
the soft excess feature below 50 keV
(model parameters: $R=10^{14}$ cm, $\Gamma=1300$).
Owing to the flat spectral shape of the extra component,
no IC component is required.
We can adopt a strong magnetic field,
which enhance the photomeson production efficiency.
In this case the flux of the extra component
is relatively low compared to the Band component,
which also decreases the required proton luminosity.
Therefore, the necessary nonthermal proton luminosity is
then not excessive and only comparable to the Band component luminosity.

\begin{figure*}[t]
\centering
\includegraphics[width=65mm]{fA3.eps}
\caption{The SSC-model fluence obtained from our
time-dependent simulation (assuming $z=1$).
The dashed line neglects absorption due to EBL.} \label{f3}
\end{figure*}

\section{LEPTONIC MODELS}

As Corsi et al. \citep{cor10} discussed, the GeV emission may be due to IC
emission from internal dissipation regions.
However, it seems difficult to explain spectral excesses
in both keV and GeV bands by IC emission.
Recently, we carry out time-dependent simulations
of photon emissions with leptonic models \citep{asa11}.
In our simulations,
as the photon energy density increases with time
because of synchrotron emission,
the SSC component gradually grows and dominate
the photon field later.
This late growth of the IC component has been
observed also in the simulations of Bo\v{s}njak et al. (2009)
\citep{bos09}.
The resultant lightcurves show delayed onset
of GeV emission, but the delay timescale would be within
the approximate timescale of the keV-MeV pulse width.
However, the longer delay compared to the pulse
timescale such as observed in GRB 080916C
is not explained by this effect only.

As shown in Fig. \ref{f3}
(model parameters: $R=6 \times 10^{15}$ cm,
$\Gamma=1000$, $B=100$ G,
$E_{\rm iso}=10^{54}$ erg,
$\varepsilon_{\rm e,min}=11.3$ GeV), the model spectrum
obtained from our simulations reproduce
both the low and high energy excesses.
When the magnetic field is weak enough,
even at the end of the electron injection,
the cooled electrons can be still relativistic.
Such cooled electrons
continue emitting synchrotron photons.
The cooling due to IC gradually becomes inefficient as
the seed photon density decreases.
Such late synchrotron emission can yield
the low-energy excess, while IC emission
makes a GeV extra component.

\begin{figure*}[t]
\centering
\includegraphics[width=80mm]{fA4.eps}
\caption{The lightcurves for the external IC model.
In the MeV band the external photons from inside region dominate,
while GeV and eV emissions are orginated from accelerated electrons
in outside dissipation region.} \label{f4}
\end{figure*}

Another possible model is the external IC emissions \citep{tom09,tom10},
which can explain the delayed onset of GeV emission.
The spatial separation between the source of the external photons
and the site of the internal shock region corresponds
to the delay timescale.
We also carry out a simulation for this model
assuming an external emission $L_{\rm seed}=10^{53}~{\rm erg}~{\rm s}^{-1}$
with the Band function:
$\varepsilon_{\rm peak}\simeq 1$ MeV in the observer frame,
$\alpha=-0.6$, and $\beta=-2.6$.
The parameters for the internal shock
are similar to those in Fig.\ref{f3} as $R=6 \times 10^{15}$ cm,
$\Gamma=1000$, $B=100$ G,
$E_{\rm iso}=3 \times 10^{53}$ erg, except for
$\varepsilon_{\rm e,min}=50.6$ MeV.
Our simulation reproduces the delayed onset of GeV emission,
GeV extra component, and softening of the Band component.
Since the external photon field in the rest frame of the emission region
is highly anisotropic, the marginally high-latitude emission contributes
the most to the flux.
Thus, the simulated GeV lightcurve shows larger delayed onset
and longer tail than that in the usual leptonic models (Fig.\ref{f4}).

\section{IMPLICATION}

The hadronic models usually require a much larger
energy of protons than observed gamma-rays
except for some examples such as GRB 090902B.
Some may consider
that the leptonic SSC models seem rather reasonable to
reproduce both the GeV and keV excesses.
However, a lower magnetic field and high Lorentz factor,
required to make an optically thin source for GeV
photons generated via IC emission,
leads to a very high minimum Lorentz factor ($\gamma_{\rm e,min}
\sim 10^4$)
for random motion of accelerated electrons.
If all electrons are accelerated in internal shock regions,
such a high value may be impossible.
Thus, the fraction of accelerated electrons should be
small in leptonic models to explain {\it Fermi}-LAT GRBs.

On the contrary, the minimum Lorentz factor of
electrons $\gamma_{\rm e,min}$
in the external IC model should be small
to adjust the energy of scattered photons.
Given the total energy, such small $\gamma_{\rm e,min}$
means large number of electrons.
If the numbers of electrons and protons are the same,
the proton energy becomes fairly large
($\sim 1.9 \times 10^{54}$ erg in the case of Fig.\ref{f4},
while the luminosity of the Band component
$L_{\rm seed}=10^{53}~{\rm erg}~{\rm s}^{-1}$).
To enhance the emission efficiency,
electron-positron plasma should be introduced in such models.

Despite the ability of our straightforward simulations to reproduce various observed
properties of the GRB prompt emission,
the discrepancy with the low-energy index $\alpha$ remains unexplained.
The injected electrons cool via synchrotron radiation,
and distribute below $\gamma_{\rm e,min}$ with
a power-law index $-2$.
The resultant photon index becomes $\alpha \sim -1.5$,
while the observed typical values are $-1.0$ or harder.
The low-energy photon index affects
the photomeson production efficiency.
We have also tried to resolve this problem \citep{asa09c,mur11}
considering continuous acceleration/heating due to magnetic turbulences
induced via various types of instabilities
such as Richtmyer-Meshkov instability \citep{ino11}.
The acceleration/heating balances with the synchrotron cooling,
so the observed low-energy spectral index is naturally explained.
Such effect should be included in the time-dependent code
to reproduce the global shape of the GRB prompt spectra
from eV to GeV.
Especially, electron injection due to hadronic processes
and succeeding acceleration by turbulences may
explain very high $\gamma_{\rm e,min}$ and
GeV emission.

We plan to develop the time-dependent code
shown here to treat hadronic processes or
continuous acceleration/heating.
Note that the results for the hadronic models shown here
were calculated based on the steady state approximation.
We will carry out simulations for
various situations involving dissipative photospheres
and internal or external dissipation or shock regions.
Moreover, the code will be useful for simulating emissions
of other high-energy sources, such as active galactic nuclei,
supernova remnant, and clusters of galaxies.

\begin{acknowledgments}
The series of our studies introduced here are
partially supported by Grants-in-Aid for Scientific Research
No.22740117 (KA), No.22540278 (SI),
and No.21540259 (TT) from the Ministry of Education,
Culture, Sports, Science and Technology (MEXT) of Japan.
\end{acknowledgments}

\bigskip