dataesr/scientific-paragraphs-categorization huggingface dataset:
g. ,  [4, 6, 30]. This is in order to obtain both for the automatic vectorization and/or hand-made digitalization all the potential boundaries of the rock-forming grains; in turn, these are useful for deriving size descriptors, shape factors, and orientations  [31] [32] [33] [34] [35] [36]  applicable to all the geosciences disciplines e. g. ,  [31, [37] [38] [39] [40] [41] [42] [43]. In recent years, the use of increasingly efficient algorithms for image processing, which are implemented in Geographic Information Systems (GIS), are giving more highly performing and encouraging results  [4, 6, [44] [45] [46] [47] [48] [49]. The highly performing results of the algorithms are synergistically integrated with the strength of the GIS, which is based on the following capabilities: (i) to manage and overlap big data structured in a database that is potentially interoperable e.
g. ,  [50] ; (ii) to integrate and process different spatial information, both in raster and vector format; and (iii) to carry out a semi-automated post-processing editing stage of vector objects. For these reasons, the use of a GIS is particularly indicated for extrapolating, handling, and analyzing fabric information from images of rocks or thin sections  [4, 6, 18, 44, 46, [51] [52] [53] , as well as allowing users to overcome the issue of linking fabric data to the thin section reference frame. Furthermore, the use of the Model Builder graphical modeler in the ArcGIS ® software allows the tuning of a designed sequence of operations to fulfill specific purposes. Generally, the algorithms used for the processing of images acquired from thin sections are based on the following: (i) edge detection techniques  [1, 4, 5, 25, 46] , which use gradient tools to detect sharp color changes and thus identify grain boundaries; (ii) region detection techniques  [4, 6, 44] , which homogenize neighboring pixels having similar color intensities, by applying focal filters within a fixed distance, in order to outline grains; (iii) threshold detection techniques  [38, 54] , which unify the range of pixels with similar color intensities to obtain a binary image composed by grains and background; and finally, (iv) a combination of all the techniques described above  [6].
The sequential automated application of the techniques mentioned above is useful to elaborate the mineral grain boundaries and grain maps, starting from a single highresolution thin section optical scan. This former stage of the procedure is carried out via the tool named Grain Size Detector (GSD), which permits delineating the grain boundaries of all the rock constituents of the thin section without determination of the mineral type. The second stage of the procedure is subordinate to the acquisition of a mineral classification map obtained via the application of the first cycle of the software Quantitative X-Ray Map Analyzer (Q-XRMA)  [21] , which permits obtaining the mineral classification of an entire thin section starting from the elemental µXRF maps. This intermediate and external stage from the MFA is necessary to allow the overlap of the two intermediate outputs useful for the application of the final tool (i.
e. , Mineral Grain Size Detector-Min-GSD), which associates a specific mineral name at the digitized polygon of the single grain. More in particular, the GSD allows users to create maps of polygon objects representing grains, with all the associated fabric parameters (e. g. , grain area, perimeter, long and short axis, aspect ratio, orientation). For the segmentation step, the GSD tool adopts the Segment Mean Shift (SMS) algorithm, which is implemented in ArcGIS ® software. The SMS algorithm identifies features (i. e. , "segments", "grains") in the input imagery by grouping adjacent pixels that have similar colors and given spatial relationships. Through the processing of a mineral classification map of the same area processed by the GSD, the Min-GSD assigns each polygon to a given mineral, and a map of the grain boundaries categorized according to the pairs of minerals that are in contact is also obtained.
Overall, we propose a novel workflow (Figure  1 ), which includes four main steps: (i) the acquisition of optical scan and X-ray maps of the entire thin section via high-resolution scanners and electron microscope/microprobe, respectively; (ii) image processing to obtain vectorized grains and classified minerals, by using the GSD and Q-XRMA tools; (iii) the georeferencing of these maps in ArcGIS ® environment; and finally, (iv) the mineralogical classification of vectorized grains, which makes available a detailed quantitative description of the rock texture. ISPRS Int. J. Geo-Inf. 2021, 10, x FOR PEER REVIEW 4 of 28 second stage of the procedure is subordinate to the acquisition of a mineral classification map obtained via the application of the first cycle of the software Quantitative X-Ray Map Analyzer (Q-XRMA)  [21] , which permits obtaining the mineral classification of an entire thin section starting from the elemental μXRF maps.
This intermediate and external stage from the MFA is necessary to allow the overlap of the two intermediate outputs useful for the application of the final tool (i. e. , Mineral Grain Size Detector-Min-GSD), which associates a specific mineral name at the digitized polygon of the single grain. More in particular, the GSD allows users to create maps of polygon objects representing grains, with all the associated fabric parameters (e. g. , grain area, perimeter, long and short axis, aspect ratio, orientation). For the segmentation step, the GSD tool adopts the Segment Mean Shift (SMS) algorithm, which is implemented in ArcGIS ® software. The SMS algorithm identifies features (i. e. , "segments", "grains") in the input imagery by grouping adjacent pixels that have similar colors and given spatial relationships.
As an application of the tool, we analyzed an amphibolite sample, a mylonitic-paragneiss and -tonalite sample, in order to extrapolate particle fabric on different metamorphic rock types. Finally, the same sandstone sample used by the ArcGIS-based edge detector of  [4]  was also processed with the MFA toolbox to compare obtained results. The particle fabric as well as the grain sizes, number of grains, mineral modal abundances, As an application of the tool, we analyzed an amphibolite sample, a myloniticparagneiss and -tonalite sample, in order to extrapolate particle fabric on different metamorphic rock types. Finally, the same sandstone sample used by the ArcGIS-based edge detector of  [4]  was also processed with the MFA toolbox to compare obtained results. The particle fabric as well as the grain sizes, number of grains, mineral modal abundances, and pairs of mineral contacts are obtained too and correctly stored within a user-friendly geodatabase.
This tool allows the user to obtain from the investigated samples some numerical information that can be displayed as derivative maps (Figures  7  and 10 ). The large number of the derived fabric parameters (e. g. , Table  2  and Supplementary Materials) permits detailed microscopic characterization of the sample thanks to a microscopic information system e. g. ,  [6]  in which each detected grain is accompanied by dimensional, geometrical, and compositional data structured in a database (Tables  2  and 3  and Supplementary Materials). Preliminary versions of the tools embedded in the Micro-Fabric Analyzer toolbox have been already successfully applied in several works. The GSD has revealed to be a valuable asset to conduct vorticity analysis and strain rate estimation on mylonites  [53] , to integrate microtomography investigations in the reconstruction of the geological evolution of metamorphic rocks  [62] , and to improve the characterization of plutonic rocks by describing specific textural features such as a potential fabric anisotropy  [63].
Conclusions We presented a new GIS-based procedure for the semi-automatic analysis of a rock thin section micro-structure. The procedure was created with the Model Builder visual programming language embedded in ArcGIS ® and is available as a Toolbox extension (Micro-Fabric Analyzer. tbx) as supplementary material. The toolbox, starting from transmitted light images acquired under crossed polarizers and micro-X-ray maps, allows grain boundary detection, mineral classification, texture characterization, and modal analysis. The toolbox can help users extract quantitative information from rocks through better quantification of the fabric parameters useful to describe different evolutionary stages of a given rock, whose features often derive from counterbalancing factors controlled by mineral crystallization, mineral reaction, grain boundary diffusion, deformation, etc.
As final remarks, we can summarize the following: (i) the toolbox constitutes a simple and a relatively fast means to derive the microstructural information of a rock if compared to a hand-tracing procedure; (ii) the Segment Mean Shift algorithm used in the GSD segmentation tool can be tuned to fit the characteristics of different rocks, and the application of a specific sequence of gradient, dilation, and thin functions improves the output reducing artifacts from the segmented image; (iii) each grain polygon is issued with a thorough set of measurements (size descriptors and shape factors) stored as attributes, and they can be easily located within the reference frame of the thin section; (iv) comparison with existing methods shows similar results in terms of edge detection and quantification of the grain parameters; (v) the grain orientation derived by the MFA is most affected by changes in the digitized polygon shape; (vi) on the basis of the georeferencing of the mineral classification map and the original thin section scan, the Min-GSD package allows an automatic statistically meaningful labeling of each polygon with a mineral phase, without the need for manual mineral identification; (vii) the entire procedure takes full advantage of GIS in terms of management and visualization of the derived data, which are stored in an easily queryable database.
Sleep disorder diagnosis relies on the analysis of polysomnography (PSG) records. As a preliminary step of this examination, sleep stages are systematically determined. In practice, sleep stage classification relies on the visual inspection of 30second epochs of polysomnography signals. Numerous automatic approaches have been developed to replace this tedious and expensive task. Although these methods demonstrated better performance than human sleep experts on specific datasets, they remain largely unused in sleep clinics. The main reason is that each sleep clinic uses a specific PSG montage that most automatic approaches cannot handle out-of-the-box. Moreover, even when the PSG montage is compatible, publications have shown that automatic approaches perform poorly on unseen data with different demographics.
To address these issues, we introduce RobustSleepNet, a deep learning model for automatic sleep stage classification able to handle arbitrary PSG montages. We trained and evaluated this model in a leave-one-out-dataset fashion on a large corpus of 8 heterogeneous sleep staging datasets to make it robust to demographic changes. When evaluated on an unseen dataset, RobustSleepNet reaches 97% of the F1 of a model explicitly trained on this dataset. Hence, RobustSleepNet unlocks the possibility to perform high-quality out-of-the-box automatic sleep staging with any clinical setup. We further show that finetuning RobustSleepNet, using a part of the unseen dataset, increases the F1 by 2% when compared to a model trained specifically for this dataset. Therefore, finetuning might be used to reach a state-of-the-art level of performance on a specific population.
6% across sleep stages  [4] , the interrater agreement strongly depends on the dataset demographics and on the sleep center where the study is recorded. As a rule of thumb, a dataset with older subjects or subjects with sleep disorders presents lower inter-rater agreements  [5]  than a dataset composed of healthy subjects  [6]. The high cost and relatively important bias in manual sleep staging have raised an interest in developing automatic sleep staging systems. Recently, deep learning has successfully reached human-performances in automatic sleep staging, in a supervised learning context  [7]  [8]  [5]  [2] [9]  [10] ; despite this, automated sleep staging methods remain unused in most sleep clinics. We identified two important factors to explain why sleep clinics still rely on manual sleep staging.
We will refer to these using the terms "input-shape incompatibility" and "accuracy-drop issue. " The input-shape incompatibility issue is practical. Each sleep clinic has a specific PSG montage that can differ according to the device used, the particularity of the targeted population, or specific requirements from a study. Automatic approaches can handle only a specific input shape they are trained on a specific dataset with a specific montage a different PSG montage will likely generate an incompatible input shape and thus the impossibility to compute an output for the model. Conversely, the accuracy-drop issue occurs when a PSG montage is compatible between two datasets. In that case, a model trained on the first dataset is able to compute an output on the second dataset but is likely to perform poorly.
This drop in performance is thought to be due to a difference in demographic distribution between the two datasets; however, another causative factor might be channel mismatch. Indeed, the recorded signals are likely to differ (e. g. , different EEG positioning, different sensor technology. ) In  [5] , the cohen's kappa (κ) of a model trained on healthy subjects drops from 84. 6 to 45. 7% when evaluated on subjects with sleep apnea; the drop was only 82. 3 to 77. 6 when the model was trained on people with apnea and evaluated on healthy subjects. Similarly, in  [11] , the balanced accuracy of a model trained on a dataset with older subjects drops by 10 points when evaluated on a dataset of young and healthy subjects. In  [12]  models trained on the EEG and EOG derivations of the MASS dataset  [13]  and evaluated on the Sleep-EDF datasets  [14]  experience macro-F1 drop of 11 points compared to their supervised learning counterpart.
This drop is likely due to the EEG derivations being different in the two datasets the drop increases to more than 20 points when the model is trained on EEG and evaluated on the EOG channels. To our knowledge, the input-shape incompatibility has never been addressed in the literature; however, several approaches have been used to try to tackle the accuracy-drop issue. In  [15]  and  [12] , the models were pre-trained on the Montreal archive of sleep studies (MASS) dataset and finetuned on the Sleep-EDF dataset; finetuning increases the performance reached in a supervised learning setting by 3 to 5 points. Similarly, in  [16] , the model was pre-trained on MASS, finetuned on the first night from a subject from Sleep-EDF and evaluated on the second night; finetuning increased performances by 6 points, and the finetuned model was only one point below the supervised learning model.
The authors used strong regularization to avoid overfitting. In  [11] , the authors aligned the observations from the source and target dataset to reduce the distribution shift between them. This method does not require labels from the target dataset, but the balanced accuracy is 10 points below the supervised baseline. However, all these methods use part of the target dataset for training, which does not remove the high fixed cost of retraining and adapting the model for a specific target dataset. Hence, they remain unaffordable for most sleep clinics. In this study, we aimed to design an approach that can be used out of the box on unseen data in sleep clinics. We first tackle the input-shape incompatibility by introducing the RobustSleepNet, a deep learning model that can handle any PSG montage, thus any input shape.
This input-invariance property allows us to tackle the second issue: the accuracydrop on unseen data. We greedily address this issue by training our model on a large corpus of eight datasets with substantial input sensors and demographic variability to increase the generalization capacity of the model. In the following section, we first present the general architecture and principles of RobustSleepNet and the height datasets used in this study. We evaluate our approach in various setups and compare our results to available literature results. Specifically, we evaluate the performance of our approach in the case of direct transfer to unseen data. We complete this evaluation with several experiments designed to evaluate the impact of some important experimental parameters.
A. Problem definition We represented the signals acquired by the PSG during a night as a sequence of 30-second epochs in R C×L. C is the number of channels of the PSG, and L = 30 × f s the number of points in the epoch. f s is the sampling frequency of the PSG signal. We assumed that f s was the same for every signal because our preprocessing included resampling each signal to the same frequency. We labeled each epoch with one of the five sleep stages, which were subsequently converted using one-hot encoding in (0, 1) 5. We defined a dataset D as a set of N scored PSG nights from different subjects recorded in the same conditions. Notably, the number of channels C D and the segment length L D was the same for every record within the dataset D. The problem was predicting the sleep stages of every night from a dataset D target using a trainable deep learning model and a set of several source datasets D sources = {D 1 , D 2 ,.
}. To do so, we benchmarked our model using three learning settings (Figure  1 ): 1) Direct Transfer (DT): we trained the model using the D sources and evaluated on D target. This is the most interesting approach since we did not use any data from D target during training. 2) Learning from scratch (LFS): we trained and evaluated the model on the dataset D target in a k-folds fashion. Most automatic sleep stage classification systems use this approach  [8]  [7]  [5]. We split the data subject-wise to avoid data leakage: when several nights were available for one subject, they were assigned to the same fold. 3) Finetuning (FT): this is a mix of both previous approaches. We first trained the model using the D sources as in the DT approach. We then trained and evaluated the model on the D target dataset in a k-folds fashion similar to the LFS setting.
B. Evaluation Once the deep learning model had predicted the sleep stages for every epoch of every night from the dataset D target we could compute a performance metric. approaches from the literature, we used the Macro-F1 score over all the epochs from a dataset. F 1 = 1 5 1≤i≤5 precision i. recall i precision i + recall i where precision i and recall i respectively denoted the precision and recall for the i-th sleep stage. We will refer to the Macro-F1 in this paper using F 1.
C. Measure of the dataset generalization and easiness To characterize the individual contribution of each dataset used in this study during DT, we defined two metrics called generalization and easiness. Given N datasets datasets, F 1(D i , D j ) denotes the F1 of a model trained on the i-th dataset, and evaluated on the j-th dataset using the DT setting. We introduced F 1 rel (D i , D j ) the relative F1 of a model trained on D i and evaluated on D j with respect to the LFS performance of this model F 1 Dj. F 1 rel (D i , D j ) = F 1(D i , D j ) F 1 Dj generalisation(D k ) = 1 N datasets -1 i =k F 1 rel (D k , D i ) easiness(D k ) = 1 N datasets -1 i =k F 1 rel (D i , D k ) The generalization of D quantifies how well a model trained on D performs on each dataset from D sources. The easiness of D quantifies how well the models trained on each D sources perform on this D.
In this way, it enables RobustSleepNet to handle an arbitrary number of input channels C D by recombining them into a fixed number of channels. It allows training on any montage and multiple datasets at the same time. One other collateral property of using attention is handling input channels in any order (channel-order invariance). The architecture is summarised in Fig 2. We implemented RobustSleepNet in PyTorch  [18]. The code, trained models and results, are publicly available at https://github. com/ Dreem-Organization/RobustSleepNet. RobustSleepNet is composed of four main blocks. The first block processes the raw signal of one epoch X ∈ R C×L , and computes its normalized short-time Fourier transform (STFT) in R C×F f f t ×L f f t. The second block encodes a segment from R C×F f f t ×L f f t into a vector R P.
F. Dealing with varying channel size during training in DT We showed how the multi-head attention part of the network could deal with varying channel sizes C D. However, it is technically more convenient to deal with a fixed number of channels for each batch of observations during training. To do so while keeping a mix of observations from several datasets in each batch, we will define in the following section a way to select a fixed C batch number of channels for a batch. C batch was sampled for each batch in C batch ∈ {1,. , C max } with C max = max d∈D (C d ) following: P(C batch = n) = 1 Cmax C=1 n C This encouraged smaller C batch sizes, which prevented the model from relying on too many channels to make a prediction. Then, we randomly sampled C batch channels for each observation with replacement if C batch > C D.
G. Inference To infer the sleep stages on a dataset D target , we evaluated the trained model on each subject with a stride of 1. For each epoch X ∈ R C×L of a record, we obtained T predictions πi due to the temporal context and the stride. As in  [8]  and  [5] , the T estimates were aggregated using a geometric average. π = exp 1 T T i=0 log(π i ) , and the predicted sleep stage used for evaluation was Unless otherwise stated, we use the consensus of the five scorers as the ground-truth hypnograms for DOD-O. [5]  describes the procedure to build the consensus. ỹ = argmax j∈[[0, Dreem Open Datasets Healthy (DOD-H):  [5]  Public dataset scored by five sleep-experts according to the AASM standards. DOD-H is composed of 25 nights from healthy subjects without any sleep-related disorder or medications.
EEG, EOG, EMG, and ECG derivations are available. Unless otherwise stated, we use the consensus of the five scorers as the ground-truth hypnograms for DOD-H  [5]. Montreal archive of sleep studies (MASS) :  [13]  We consider only the SS1 and SS3 cohorts from MASS. We exclude SS2, SS4, and SS5, which use the R&K scale with 20 seconds epochs. Both cohorts were scored according to the AASM standards. The SS1 cohort comprises 53 nights from elderly subjects (some of whom have sleep-related disorders) and the SS3 cohort of 62 nights from healthy subjects. A complete PSG montage was used. We report performances on the two subsets. Sleep-EDF dataset :  [14]  The Sleep-EDF dataset is composed of two studies, Sleep-Telemetry (ST) and Sleep-Cassette (SC). ST includes 44 nights from 22 subjects with trouble falling asleep.
The in-bed setup where only epochs between lights-off and lights-on time are considered  [26]   [12]. MrOS :  [27]  [28]  [29]  MrOS is a child study analyzing the link between osteoporotic Fractures and sleep. The nights were scored by sleep experts from six different sleep centers according to the AASM standard. We consider the 586 nights from the second Sleep Study MrOS-2 with EEG, EMG, and EOG derivations. The Multi-Ethnic Study of Atherosclerosis (MESA) :  [30]  [31] The Multi-Ethnic Study of Atherosclerosis dataset contains 2,237 nights from subjects likely to suffer from cardiovascular diseases aged from 54 to 95. The nights are scored according to the AASM standard by different scorers from six sleep centers. The subjects are not screened for sleeprelated pathologies and may suffer from various pathologies.